?
Solved

fork: Resource temporarily unavailable

Posted on 1997-05-06
2
Medium Priority
?
1,411 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Accepted Solution

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

0
 

Expert Comment

by:prade
ID: 1292801
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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

800 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