I am new to Linux Systems Programming and as the title suggests, I am trying to identify if a particular process is getting terminated by SIGTERM, SIGQUIT or SIGINT. I am trying to identify between them using the status of the process which is returning 2 and 15 for SIGINT and SIGTERM respectively as it is supposed to be, but instead it is returning 131 for SIGTERM where it should be 3.
Distro Used: Ubuntu
#include <iostream> #include <signal.h> #include <wait.h> using namespace std; int main() { int pid,status; pid=fork(); if (pid==0) while(1); if (pid!=0) { if(getchar()){ //kill(pid,SIGINT); //status 2 //kill(pid,SIGQUIT); //status should be 3 but coming out 131 why? //kill(pid,SIGTERM); //status 15 } wait(&status); if (WIFSIGNALED(status)) if (status==2) cout<<"Terminated by SIGINT"<<endl; else if (status==15) cout<<"Terminated by SIGTERM"<<endl; else if (status==131 /*|| status==3*/) cout<<"Terminated by SIGQUIT"<<endl; } return 0; } [link] [comments]