My child proccess can't start to work. I need to pass signal and execute readUsual
function.
This is a small piece of code:
int main()
{
pid_t pid2 = fork();
if (pid2 < 0)
printf("Can't create child process\n");
else if (pid2==0)
{
//this block never execute
printf("Process2, pid=%d\n",getpid());
signal(SIGUSR1,readUsual);
}
else
{
kill(pid2,SIGUSR1);
printf("%s\n","Proccess1 end");
for(;;);
}
return 0;
}
You need to either add synchronization in some way, or call
signal()
before yourfork()
.With your current code, you have no way to be sure child process call
signal()
before it receive the signal. Receiving the signal before the instruction to handle it will stop the child process.Example:
Example of output with this code: