Subject: Problem with fork
From: [email-masked] (Mike Bernson)

13 Apr 1997 17:31:35 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 3.01 (X11; I; BSD/OS 3.0 i386)
Original-To: [email-masked]
Original-Sender: [email-masked]

I am getting a permision problem when trying to fork.

Does anyone known why I would get a EACCES from fork system
call. Is there any way to findout what it trying to get access
to.

I am using thing under window 95.

#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include "tol.h"

#define max(a,b)        ((a) > (b) ? (a) : (b))

int     execute(file_name, args)
char    *file_name;
char    *args[];
{
        int     status;
        pid_t   pid;
        int     i;
        int fd_max;

        fd_max = 20;

        /*
         * Loop trying to fork until we are able to do so. If the
         * fork fails then sleep some random amount of time between
         * 5 and 36 seconds.
         */
        do {
                /*
                 * Create a process and do the right thing for parent.
                 * child, and errors
                 */
                switch(pid = fork()) {
 
                /*
                 * error creating new child/process. Log an error
message
                 * and sleep for a random amount of time.
                 */
                case -1:
                        log_it("execute: fork failed %s",
strerror(errno));
                        sleep((rand() & 0x1f) + 5);
                        break;

                /*
                 * child process. Close all the open file expect stdin,
                 * stdout, stderr. Once this is done the execute the
                 * new program.
                 */
                case 0:
                        for(i=3; i < fd_max; i++)
                                close(i);

                        execvp(file_name, args);
                        _exit(100 + errno);

                /*
                 * parent task. Wait for the child to exit and then
collect
                 * exit status of child. If exist status greater then
100
                 * then the child did not run.
                 */
                default:
                        status = 1;
                        waitpid(pid, &status, 0);

                        if (WEXITSTATUS(status) > 100)
                                log_it("execute: Could not execute
%s(%s)\n",
                                         file_name,
                                         strerror(WEXITSTATUS(status) -
100));

                }
        } while(pid < 0);
 
        /*
         * Let caller known if the child run and executed ok.
         */
        if ((WIFSIGNALED((status)))) {
                log_it ("execute: %s died with signal\n",
                         file_name);
                return -1;
        }
 
        if (!WIFEXITED(status) )  {
                log_it ("execute: %s did not call exit\n", file_name);
                return -1;
        }

        if (WEXITSTATUS(status) != 0)
                return -1;
        else
                return 0;
}
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".