#include Operating Systems - Interprocess Communication - Signals Operating Systems - Interprocess Communication - Signals Operating Systems - Interprocess Communication - Signals Process Management 1 Process Management InterprocessusCommunication and Memory Management 3 • Interprocesses communication #include<signal.h> int kill(int pid, int nsig) : sends the signal nsig to the process with the pid It returns 0 or -1 Pid=35 P2 When P2 receives the signal SIGINT, it will execute the hundler associated #include <signal.h> #include <unistd.h> #include <unistd.h> // Sets an alarm after nb_sec seconds. It will send a SIGALARM signal to the calling Too late Signal(SIGALARM, &beep); Write a C program that executes a command with its arguments after protecting the Application 2 Write a program C that creates a child. The child prints odd integers from 1 to 100Uploaded by
Aeram El Heni Copyright:
Available Formats
Uploaded by
Aeram El Heni Original Description:
Original Title
Copyright
Available Formats
Share this document
Did you find this document useful?
Is this content inappropriate?
Copyright:
Available Formats
Uploaded by
Aeram El Heni Copyright:
Available Formats
Operating Systems (OS)
Inter Process Communication Dr. Najar Yousra
Email : yousra.najar@isi.utm.tn
Yousra.najar@medtech.tn Med Tech First Year Eng 2023/2024
Road Map
Introduction to operating systems
Synchronisation File System Management
CS303 Dr. Najar Yousra
Fall 2021 2
Week 4 (25/09/2023)
The Lecture explains some interprocesses
Communication tools : Signals, pipes and
shared memory. The student will be able to understand the
mechanism of the IPC and to writer C
programs handling them.
Outlines of the section
• Signals
• Pipes
• Shared Memory
1. Interprocesses Communication
Interprocesses communication Processes executing concurrently in the operating system
may be either independent processes or cooperating
processes.
A process is independent if it cannot affect or be affected
by the other processes executing in the system. Any
process that does not share data with any other process
is independent.
A process is cooperating if it can affect or be affected by
the other processes executing in the system.
Processus could
◦ Communicate with signals
◦ Share data and information
Interprocesses communication (IPC) Signals are the minimal level of communication between
processes. Pipes, messages, memory are used to communicate data
between processes.
Interprocesses communication
1. Signals Signals are used to notify a process of synchronous or
asynchronous events. Normally, they are software interruptions.
Hardware interruption (from devices ) are interrupts.
Signals are a limited form of inter-process communication (IPC).
When a signal is sent, the operating system interrupts the target
process’ normal flow of execution to deliver the signal.
Each signal is associated to a default routine (An action to
execute).
A signal is identified by an integer value < NSIG. Instead of using
the numeric values directly, the named constants defined
in signals.h should be used.
Interprocesses communication
1. Signals
Interprocesses communication
1. Signals (example UNIX)
$kill -l
Interprocesses communication
1. Signals
A signal has a state it could be : • Delivired : sent to the process
• Masked : not treatable by the processes
• Waiting : sent, not masked but not yet treated
• Pending : sent and masked
• Notified : sent and executing its treatment
• Treated: sent, not masked and finished its
treatement
Interprocesses communication
1. SignalsData structures to manage signals Process
PIB
in the Process PCB are three :- Sent signals vector : 1 for Delivered Mask
Table of received signals signals rotines
- Mask vector : 1 for masked
signals
- Handlers vector : a pointer to
the function to execute when
the signal is received (handler)
Interprocesses communication
1. Signals
Sending a signal
passed as argument. Sending the signal number 2 (SIGINT) to the process with
P1 pid = 35
kill(SIGINT, 35)
kill(2, 35)
SIGINT
with it (which is ending its execution).
Interprocesses communication
1. Signals
Handling signal : Changing the behaviour of a process when it receives a signal.
typedef void (*sighandler_t)(int);
Sighandler_t signal(int signum, sighandler_t handler); void sig_hand(int sig)
int main(void) { printf (« received signals %d \n",sig);}
{ signal(SIGINT, SIG_DFL);
raise (SIGINT); int main(void)
sleep (10); { signal(SIGINT, &sig_hand);
exit(0); raise (SIGINT);
} sleep (10);
exit(0);} int main(void) Executes a new routine
{ signal(SIGINT, SIG_IGN);
raise (SIGINT);
sleep (10); Restaures default
routine
exit(0);
} Ignores the signal
Interprocesses communication
1. Signals
Pause / sleep / alarmsleep() and pause() could be used :
int pause(void) // blocks the calling process until the reception of any signal int sleep(unsigned int n) // blocks the calling process for n seconds
unsigned int alarm(unsigned int nb_sec);
process after nb_sec seconds to kill him. You can change the treatment.
Interprocesses communication
1. Signals
Example
Interprocesses communication
1. Signals
Application 1
process from the SIGHUP signal.
and the parent prints even intgers from 1 to 100. Printed integers must be ordered.
Use signals.To manage them.You might also like