Solved

fork: Resource temporarily unavailable

Posted on 1997-05-06
2
1,399 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 169
Folder Comparison 12 55
modThree challenge 4 112
sumHeights  challenge 17 79
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…
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.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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