I’m trying to run a program inside a program, in a non blocking way using fork().
pid = fork();
//check for errors
if (pid < 0) {
exit(1);
}
//the child process runs the gulp
if (pid == 0) {
if (execv("/home/gulpSniffer/programname", args) < 0) {
exit(1);
}
//child is supposed to block here
}
//father is supposed to continue its run from here
However, the invocation of the program in the child’s process blocks the whole program, and the father’s code segment is not executed because it’s blocked by the child.
Does anyone have an idea of why?
Thanks
Do you
waitfor the child process to terminate in the parent? That will block until a child actually terminates.Or maybe you have your own SIGCHLD signal handler, which blocks somehow?
Can’t think of any other way a child can make parent block (well, except any inter-process locking mechanism, but you would know if you used these).
Also, if you don’t care when child process ends, you should set
signal(SIGCHLD, SIG_IGN);That way system should automatically reap the exited child, and you don’t end up with zombie.