#include <sys/types.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <signal.h>
#include <iostream>
#include <unistd.h>
int main(){
signal(SIGCHLD,SIG_IGN );
pid_t pid = vfork();
if(pid <0){
std::cout<< "Error: Fork failed at main!!!";
exit(1);
}else if (0 == pid){
char * cmd[] ={(char*)"../work/C++11/Prj_LargeFile/script/Logger.pl",NULL};
//char * cmd[] = {(char*)"pwd",NULL};
//char * cmd[] = {(char*)"/usr/bin/perl",(char*)"../work/C++11/Prj_LargeFile/script/Logger.pl",NULL};
execvp(cmd[0],cmd);
_exit(0);
}
}
I want to have orphan child process which will run a perl script in the backgroud and I want the parent process to be completed without waiting on its child. Hence I have used signal(SIGCHLD,SIG_IGN ) at the beginning to ignore child signal on completion and to avoid zombies. But when i am running the code its giving me error as Can't ignore signal CHLD, forcing to default. . On the other when i am running those commented lines instead its running with the desired signal. what is the reason of that?