Operating Systems - Interprocess Communication - Signals
Operating Systems - Interprocess Communication - Signals
Process Management
Inter Process Communication
1
Road Map
Introduction to operating systems
Process Management
InterprocessusCommunication and
Synchronisation
Memory Management
3
Outlines of the section
• Interprocesses communication
• Signals
• Pipes
• Shared Memory
1. Interprocesses Communication
Interprocesses communication
#include<signal.h>
int kill(int pid, int nsig) : sends the signal nsig to the process with the pid
passed as argument.
It returns 0 or -1
Pid=35 P2
kill(SIGINT, 35)
kill(2, 35)
SIGINT
When P2 receives the signal SIGINT, it will execute the hundler associated
with it (which is ending its execution).
Interprocesses communication
1. Signals
Handling signal : Changing the behaviour of a process when it receives a signal.
#include <signal.h>
typedef void (*sighandler_t)(int);
Sighandler_t signal(int signum, sighandler_t handler);
#include <unistd.h>
int pause(void) // blocks the calling process until the reception of any signal
#include <unistd.h>
unsigned int alarm(unsigned int nb_sec);
// Sets an alarm after nb_sec seconds. It will send a SIGALARM signal to the calling
process after nb_sec seconds to kill him. You can change the treatment.
Interprocesses communication
1. Signals
Example
Too late
Signal(SIGALARM, &beep);
Interprocesses communication
1. Signals
Application 1
Write a C program that executes a command with its arguments after protecting the
process from the SIGHUP signal.
Application 2
Write a program C that creates a child. The child prints odd integers from 1 to 100
and the parent prints even intgers from 1 to 100. Printed integers must be ordered.
Use signals.To manage them.