Featured Post

Tuesday, May 10, 2016

UNIX program to send user defined signals to a process and print signal number according to the sent signal

#include<stdio.h>
#include<unistd.h>
#include<sys/stat.h>
#include<signal.h>
#include<sys/wait.h>
static void sig_usr(int signo)
{
  if(signo==SIGUSR1)
   printf(" recived signal1\n");
  else if(signo==SIGUSR2)
  printf("Recvied signal2\n");
  else
   printf("recived signal number %d\n",signo);
 }
int main()
{
  if(signal(SIGUSR1,sig_usr)==SIG_ERR)
  {
    printf("error");
   return -1;
 }
   if(signal(SIGUSR2,sig_usr)==SIG_ERR)
  {
  printf("error");
 }
for(;;)
pause();
return 0;

}


/home/netsem2014/~ cc signalnumber.c
/home/netsem2014/~ ./a.out&
[5]   2332

/home/netsem2014/~ kill -SIGUSR1 2332
recived signal1




http://cjuschools.blogspot.in/



reliable signal handling, sigur1 sigusr1, kill and raise signals.

No comments:

Post a Comment