View Full Version : sigprocmask and sigsuspend usage

02-16-2011, 12:17 PM
Iam trying to understand sigsuspend and sigprocmask usage / behaviour.

My below program do register SIGUSR2 for signal hanlder by using sigaction.

Then sigprockmask block on SIGINT , ( here i just got confused like what does SIG_BLOCK mean exactly is it like the process can now respond to this signal as it default behaviour.
If any body gives a bit more info on this it would be really help full in understanding the conept)

sigsuspend on the SIGUSR1 i.e the process will get suspended untill it gets SIGUSR1 signal.

but in my case

if i send SIGINT signal process is getting terminated.

if i send SIGUSR2 it gets terminated with following output

program start:
In critical region
I caught the signal 12
User defined signal 1

here iam no where printing this "User defined signal 1" how is getting printed?

can any body let me know where my interpretation is going wrong.

Iam following apue2 ( advance programing in unix environment second edition)

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>

void mysigHandler(int signo)
printf("I caught the signal %d \n",signo);

int main()
struct sigaction act,oact;
sigset_t newmask,oldmask,waitmask;

printf("program start:\n");

act.sa_handler = mysigHandler;
act.sa_flags = 0;

if(sigaction(SIGUSR2,&act,&oact) < 0)
return (int)(SIG_ERR);


if(sigprocmask(SIG_BLOCK,&newmask,&oldmask) < 0)
printf("SIG_BLOCK ERROR\n");

printf("In critical region \n");

if(sigsuspend(&waitmask) != -1)
printf("sigsuspend error \n");

printf("after return from sigsuspend\n");

if(sigprocmask(SIG_SETMASK,&oldmask,NULL) < 0)
printf("SIG_SETMASK error\n");

printf("program exit \n");