



































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




































1
2
4
Explicit & Implicit
Module Loading/Unloading
8
10
11
14
Ch 21.9 IPC: Interprocess Communication
17
19
// Examine and change a signal action
int pause(void); // wait for a signal int kill(pid_t pid, int sig); // send a signal unsigned int alarm(unsigned int seconds);
20
/* signal.c starts */ #include <signal.h> #include <stdio.h> #include <sys/types.h> #include <unistd.h> void handleSIGINT(int sig) { printf("received SIGINT (sig= %d)\n", sig); fflush(stdout); } void handleSIGQUIT(int sig) { printf("received SIGQUIT (sig= %d)\n", sig); fflush(stdout); } void handleSIGUSR1(int sig) { printf("received SIGUSR1 (sig= %d)\n", sig); fflush(stdout); } void handleSIGTSTP(int sig) { printf("received SIGTSTP (sig= %d)\n", sig); fflush(stdout); } void handleSIGFPE(int sig) { printf("received SIGFPE (sig= %d)\n", sig); fflush(stdout); }
int main() { printf("pid of handler process is: %d \n", getpid()); signal(SIGINT, handleSIGINT); signal(SIGQUIT, handleSIGQUIT); signal(SIGTSTP, handleSIGTSTP); signal(SIGUSR1, handleSIGUSR1); signal(SIGFPE, handleSIGFPE); for (;;) { printf("Waiting for signals... \n"); printf ("Enter 't' to test FPE exception; 'e' to exit \n"); int c = getchar(); getchar(); // consume newline if (c == 'e') break; // No FPE is caused here float x = 100.0; float y = x/0.0; printf("y= %f \n", y); // FPE i s caused h ere-- also causes a n infinite l oop int i=1/0; } }