Mail Archives: cygwin/1997/04/13/17:31:35
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
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -