Signal Ipc PDF
Signal Ipc PDF
Signal Ipc PDF
Lecture 7: Signals
Omid Ardakanian
oardakan@ualberta.ca
University of Alberta
• Signals
- Generation
- Disposition
- Blocking
‣ definition of core dump: a memory image of the process is left in a file named
core in the current working directory of the corresponding process
‣ the target process asked (using the signal mask) the kernel to block that signal
‣ the target process asked (using the signal mask) the kernel to block that signal
• the kernel wants to notify a process that its execution has led to a hardware
exception (e.g., divide by zero, floating-point overflow, segmentation fault)
• the kernel wants to notify a process that its execution has led to a hardware
exception (e.g., divide by zero, floating-point overflow, segmentation fault)
• the kill command or the kill(pid_t pid, int sig) system call is
used
• the kernel wants to notify a process that its execution has led to a hardware
exception (e.g., divide by zero, floating-point overflow, segmentation fault)
• the kill command or the kill(pid_t pid, int sig) system call is
used
‣ only if it has permission: the real or effective user ID of the receiver is the same as
that of the sender
- a process can send a signal with accompanying data to another process (just like IPC)
‣ only if it has permission: the real or effective user ID of the receiver is the same as
that of the sender
- a process can send a signal with accompanying data to another process (just like IPC)
‣ it returns only when a signal was caught and the signal-catching function returned
2. SIG_DFL: let the default action happens (in most cases terminate process or
terminate process with a core dump; in some cases ignore)
‣ a signal handler can return or call exit; if it returns the normal sequence of
instructions continues executing
2. SIG_DFL: let the default action happens (in most cases terminate process or
terminate process with a core dump; in some cases ignore)
‣ a signal handler can return or call exit; if it returns the normal sequence of
instructions continues executing
• portability problem: behaviour varies across UNIX versions (use sigaction instead)
• portability problem: behaviour varies across UNIX versions (use sigaction instead)
#include <stdio.h>, <unistd.h>, <signal.h>
int i;
void quit(int code) {
fprintf(stderr, "\nInterrupt (code= %d, i= %d)\n", code, i);
}
int main (void) {
if(signal(SIGQUIT, quit) == SIG_ERR)
perror(“can′t catch SIGQUIT”);
for (i= 0; i < 9e7; i++)
if (i % 10000 == 0) putc('.', stderr);
return(0);
} O. Ardakanian, CMPUT379, Fall 2019 !8
POSIX signal environment
• examining or modifying the action associated with a particular signal (except
for SIGKILL and SIGSTOP)
- sigaction( )
- this function supersedes the signal( ) function from earlier releases of the UNIX System
- this function supersedes the signal( ) function from earlier releases of the UNIX System
- this function supersedes the signal( ) function from earlier releases of the UNIX System
- when a signal is caught and the handler is entered, the current signal is automatically added to
the signal mask of the process; this is to prevent subsequent occurrences of that signal from
interrupting the signal handler
- this function supersedes the signal( ) function from earlier releases of the UNIX System
- when a signal is caught and the handler is entered, the current signal is automatically added to
the signal mask of the process; this is to prevent subsequent occurrences of that signal from
interrupting the signal handler
• returning the set of signals that are blocked from delivery and currently
pending for the calling process
- sigpending( )
// uncomment the next line to break the loop when signal is received
// exit(1);
}
int main() {
struct sigaction sa;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sa.sa_handler = signal_callback_handler;
sigaction(SIGINT, &sa, NULL); // we are not interested in the old disposition
// uncomment the next line to break the loop when signal is received
// exit(1);
}
int main() {
struct sigaction sa;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sa.sa_handler = signal_callback_handler;
sigaction(SIGINT, &sa, NULL); // we are not interested in the old disposition
- the child starts off with a copy of the parent’s memory image, so the
signal-handler is defined in the child
- the child starts off with a copy of the parent’s memory image, so the
signal-handler is defined in the child
12
Cooperating processes
• any two processes are either independent or cooperating