Nan Xiao
Nan Xiao

Reputation: 17477

Why doesn't the program inherit the signal dispositions of bash?

I use the following C program to test signal behaviors on Solaris 10:

#include <stdio.h>

int main(void)
{
        sleep(100);
        return 0;
}

Run it in command line:

bash-3.2# ./test

Then use psig to check the signal behaviors of the test process:

bash-3.2# psig 11918
11918:  ./test
HUP     default
......
CONT    default
TTIN    default
TTOU    default
......

All the signal dispositions are default.

Use grep command to get the parent process of test:

 root 11918 17894   0 15:28:41 pts/25      0:00 ./test

Then use psig to check the signal behaviors of the parent of test process (bash):

bash-3.2# psig 17894          
17894:  bash
......
QUIT    ignored
......
TTIN    ignored
TTOU    ignored
......

Per my understanding, I think the bash should call fork to generate test, according to fork, the child process should inherit the signal dispositions.
Why doesn't the program inherit the signal dispositions of bash? Thanks in advance!

Upvotes: 0

Views: 264

Answers (1)

Jean-Baptiste Yun&#232;s
Jean-Baptiste Yun&#232;s

Reputation: 36401

Catched signals behaviour is not inherited across exec(). But OpenGroup's exec manual says :

Signals set to the default action (SIG_DFL) in the calling process image shall be set to the default action in the new process image. Except for SIGCHLD, signals set to be ignored (SIG_IGN) by the calling process image shall be set to be ignored by the new process image.

So your process signal behaviour is such because bash set it so before execing; which is reasonable.

Upvotes: 2

Related Questions