Header file:
signal.h
Synopsis:
typedef void (*sighandler_t)(int);
sighandler_t signal(int signum, sighandler_t handler);
sighandler_t signal(int signum, sighandler_t handler);
Description:
It sets the disposition of signal signum to handler and finds how to handle the subsequent signals.
Sample program for signal in C:
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
/*
* ./a.out &
* kill -SIGUSR1 3218
* kill 3218
*/
static void sig_alarm(int signo) {
if(signo == SIGUSR1)
printf("SIGUSR1 catched\n");
}
int main() {
if(signal(SIGUSR1, sig_alarm) == SIG_ERR)
printf("Unable to catch SIGALARM\n");
while(1) {
sleep(5);
}
}
#include<stdlib.h>
#include<signal.h>
/*
* ./a.out &
* kill -SIGUSR1 3218
* kill 3218
*/
static void sig_alarm(int signo) {
if(signo == SIGUSR1)
printf("SIGUSR1 catched\n");
}
int main() {
if(signal(SIGUSR1, sig_alarm) == SIG_ERR)
printf("Unable to catch SIGALARM\n");
while(1) {
sleep(5);
}
}
Output:
jp@jp-VirtualBox:~/cpgms/signals$ ./a.out &
jp@jp-VirtualBox:~/cpgms/signals$ kill -USR1 2367
jp@jp-VirtualBox:~/cpgms/signals$ kill -USR1 2367
SIGUSR1 catched
jp@jp-VirtualBox:~/cpgms/signals$ kill 2367
[1]+ Terminated ./a.out
[1]+ Terminated ./a.out
It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
ReplyDeleteData Science Interview Questions
Angular JS Interview Questions
Big Data Training in Velachery
AWS Certified Developer
Best Resource of Learning Devops
Blueprism Interview Questions
Automation Anywhere Interview Questions
Do you need Finance? Are you looking for Finance? Are you looking for finance to enlarge your business? We help individuals and companies to obtain finance for business expanding and to setup a new business ranging any amount. Get finance at affordable interest rate of 3%, Do you need this finance for business and to clear your bills? Then send us an email now for more information contact us now via (financialserviceoffer876@gmail.com) whats-App +918929509036 Dr James Eric Finance Pvt Ltd Thanks
ReplyDelete