c++ SIGCHLD create a wrong system call return

35 Views Asked by At

This is my code (it's just an example)

int a = system("pwd");
printf("pwd with return: %d\n", a);
cout << "errno is " << errno << "\n";

signal(SIGCHLD, SIG_IGN);

a = system("pwd");
printf("pwd with return: %d\n", a);
cout << "errno is " << errno << "\n";

I just run "pwd" command using system call before and after "SIGCHLD" and I get two different result:

<actual path>
pwd with return: 0
errno is 0
<actual path>
pwd with return: -1
errno is 10

In both case the command is executed properly.

Why signal(SIGCHLD, SIG_IGN); creates this issue? Is there a way to avoid it?

0

There are 0 best solutions below