Results 1 to 5 of 5
Hello,
i am using the sigaction function to handle the SIGCHLD signal.Is it possible to use a class member function as the handler function (the sa_handler member of the sigaction ...
- 03-03-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 9
Handling a signal with a class member function
Hello,
i am using the sigaction function to handle the SIGCHLD signal.Is it possible to use a class member function as the handler function (the sa_handler member of the sigaction structure)?
The function's signature is:
I could use a static member function with such a signature,but i wouldn't be able to pass an "handle" to the actual object instance.Code:void (*sa_handler)(int);
Is a global variable the only solution to this? Or is there some trick i could use?
Thanks in advance!
- 03-04-2009 #2
Just curious...why does it have to be a class member?
- 03-04-2009 #3Just Joined!
- Join Date
- Mar 2009
- Posts
- 9
Just cause i would like to avoid global stuff

But if that's the only way....oh well,i tried
- 03-04-2009 #4
Are you saying you avoid all functions....even class member functions
- 03-10-2009 #5Just Joined!
- Join Date
- Mar 2009
- Posts
- 9
Ok,so now i'm using a global variable to keep track of the pid of interest and a static member function to handle the SIG_CHLD signal.
The member function is:
I have a further question.Code:void MyClass::CallWaitChildProcess(int signo) { int status, child_val; if (waitpid(g_ChildProcessPid, &status, WNOHANG) < 0) { return; } if (WIFEXITED(status)) { child_val = WEXITSTATUS(status); printf("process pid:%d --> exited normally with status %d\n", g_ChildProcessPid,child_val); } }
I only want to handle the SIG_CHLD generated from the external program i run,maintaining the default behaviour for the SIG_CHLD signals generated from other child processes.So far,the application doesn't fork any other child process,but i can't exclude that in the future someone will add them,so i want these eventual future child processes to be handled in the default way (i.e. being ignored).
Should i change the CallWaitChildProcess function or waitpid will do the job,"excluding" unrecognized pids?


Reply With Quote