I do dome research regarding signal processing. In this particular case, I'm interested in SIGTSTP on Linux (3.0.101 on SLES 11). I wrote a small program that catches SIGTSTP and prints the parent PID and PID of the process that sent the signal.
Here is what I see:
If I use kill -TSTP, then the PID of the submit process is the PID of the shell in which I ran the kill command, as expected.
If I type ctrl + z in the shell, the PID of the send process is 0, but I expected the PID of the shell in which I pressed ctrl + z (and I ran the trap program)
Does anyone know why this is happening? Shouldn't there be 0 PIDs of some special kernel-only processes? The Sigaction documentation reports that signals sent by kill will fill in the si_pid field, but command line shortcuts are not mentioned. Perhaps si_pid = 0 means "unspecified sender".
This is my capture program.
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
#include<unistd.h>
#include<string.h>
void tstp_handler(int num, siginfo_t* info, void* context)
{
pid_t ppid = getppid();
printf("\nReceived TSTP. pid %d ppid %d\n", info->si_pid, ppid);
}
int main(void)
{
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_sigaction = tstp_handler;
action.sa_flags = SA_SIGINFO;
sigaction(SIGTSTP, &action, NULL);
printf("Registered\n");
printf("My PID is %d\n", getpid());
while(1)
sleep(1);
return 0;
}
Thanks and best regards
source
share