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
Solved

fork: Resource temporarily unavailable

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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