|
The contents of this page are licensed under the following license
Operating System
Signals -- interrupt from a keyboard |
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
void end(int signo)
{
printf("\n\nInterrupt from keyboard!\n");
exit(0);
}
int main()
{
/* signal -- SIGINT -- handling */
signal(SIGINT, end);
/* infinite loop */
while(1);
}
|
|
Signals to a child process |
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
int end = 0;
void sigservice(int signo)
{
printf("Signal!\nEND!\n");
end = 1;
exit(0);
}
int main()
{
int pid;
if ((pid=fork()) == 0)
{
/* signal -- SIGINT -- handling */
signal(SIGINT, sigservice);
while(end == 0);
}
printf("Waiting...\n");
sleep(5);
printf("Sending signal no 2 to the child process [PID=%d]\n", pid);
kill(pid, 2);
}
|
November, 29th 2006
© Michał Kalewski