Semaphore mechanism using C language Example:

Semaphore mechanism using C language Example:

#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>

void sigroutine(int signo){
    switch(signo){
        case 2:
        the printf ( " test signal sent flowers Recognition System \ n- " );
         BREAK ;
         default :
        the printf ( " other signals sent \ n- " );
         BREAK ;
    }
}
int main(){
    int sig=getpid();
    printf("process is %d\n",sig);
    Signal (SIGHUP, sigroutine); // send a signal recognition system call flowers 
    signal (SIGINT, sigroutine);
    the kill ( 21256 , SIGINT); // change the corresponding PID 
    the kill (SIG, SIGHUP);
     return  0 ;
}

 

Guess you like

Origin www.cnblogs.com/ming-4/p/11908362.html