sigsuspend is a function that changes the mask and suspends the process until a new signal is delivered, but what surprised me is that the pending signals are being delivered also after the sigsuspend.
For example: while the process is sleeping (5 sec), a ctrl-z will not execute the SIGTSTP handler because it's masked, but after the sigsuspend the signal is received automatically so the sigsuspend executes the pending signal handler also, it's right? `
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
void handlerSIGTSTP()
{
printf("I have recieved the signal \n");
}
int main()
{
sigset_t mask;
sigset_t ancien;
signal(SIGTSTP,handlerSIGTSTP);
sigaddset(&mask,SIGTSTP);
sigprocmask(SIG_SETMASK,&mask,&ancien);
printf("J'entre en sleep\n");
sleep(5);
printf("J'entre en suspend\n");
sigsuspend(&ancien);
}
Execution:
J'entre en sleep
^ZJ'entre en suspend
J'ai recu le signal maintenant