Solved

fork: Resource temporarily unavailable

Posted on 1997-05-06
2
1,375 Views
Last Modified: 2013-12-26
Hi,

This is a PIC related problem(at least I think it is), please
look at it and help if you can.  

The system is IRIX6.2 on Indigo2, compiler is C++ 7.1.

I needed a function that starts a child process, and returns the
pid and output of the child process.  Since there is no such a
function in unix, I wrote my own using pipe(to pass output back
to parent from child), fork(to create the child process, and to
get the child pid), and exec(to replace the child process with
the specified system command).

Then I wrapped this function in a daemon that accepts requests from
a message queue. My other applications can send system cmd to the
daemon and get pid and output of the new process back.  Since
we are not using multithreading, this is very helpful to manage
multiple processes.

However, after running the daemon after a while, the program can't
fork any more and gives: "fork: Resource temporarily unavailable".
After that, "no more process available" messages are given by
the shells.  Everything will be back to normal after this daemon
is stopped.

I have checked that the virtual swap space has >100M free, the
number of processes is <20 for the user and <100 for the system.

What kind of resources is used out?  Could it be caused by the
message queue that I am using?  


The function looks like this:
char *system1 (char *cmd, int *pid, int needoutput)
{
    int pfd[2];
    FILE *fd;
    pid_t child;
    char *out, buff[100];

    if(pipe(pfd) < 0){...}      //
    if ((child = fork ())<0){...}
    if (child == 0){
        dup2(pfd[1],1);
        close(pfd[0]);

        execv() or execvp()     // replace child with cmd
    }else{
        close(pfd[1]);
        *pid = child;           // return child pid

        if(needoutput){
          if (!(fd = fdopen(pfd[0],"r"))){...}
          if (fgets(buff,100,fd)){
                // processing child output
                // allocate and set out string
          }
          fclose(fd);
        }
        close(pfd[0]);
        return out;             // return child output
    }
}


Please give advice!  Thanks!

0
Comment
Question by:ocean
  • 2
2 Comments
 

Accepted Solution

by:
prade earned 200 total points
Comment Utility
You are running out of processes (which is limited under UNIX), as the child processes become zombies.

0
 

Expert Comment

by:prade
Comment Utility
try out the UNIX FAQ section 1.6 in the Web:
http://www.whitefang.com/unix/faq_2.html#SEC13
or the mirror at http://www.erlenstar.demon.co.uk/unix/
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now