Currently I am programming a shell and I use the waitpid() function for my children processes.
I also installed a signal handler so I can trap the SIGINT (CTRL+C) signal.
So what I want now is when someone presses the SIGINT (CTRL+C) signal it should leave the waitpid() functions and keep going as usually.
I am looking for a function who can help me about that.
Install your signal handler without the SA_RESTART flag:
void handler( int sig, siginfo_t *si, void *arg )
{
...
}
...
struct sigaction newact;
memset( &newact, 0, sizeof( newact ) );
sigemptyset( &newact.sa_mask );
newact.sa_flags = SA_SIGINFO; // note that **lack** of SA_RESTART
newact.sa_siginfo = handler;
sigaction( SIGINT, &newact, NULL );
You'll have to add error checking to that, and note that you will now have to handle interrupted calls in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With