Threads, Inter Process Communication
This session is dedicated to threads and to the communication between threads and processes.You don't have to submit source files or reports for this sessions. For this session, you will need to log into a PC running Linux. If you are at Eurecom, simply log on a PC of rooms 52.
I. Why using threads?
- Open the slides on Threads
- Watch the video on an introduction to threads
II. Example of multithreading
- Open the slides on Threads
- Watch the video on examples of threading models
III. Inter process / thread communication
- Open the slides Threads, last section
- Watch the video on IPC
- I often say that this is very important to test the return values of functions. In the code of the signal sender, I test the return value of the syscall "kill". Using manual pages, find at least three cases for which "-1" is returned by "kill".
- An invalid signal was specified
- The process does not have permission to send the signal to any of the target processes
- The process or process group does not exist
- Complete/adapt the following short C program to show three different errors of "kill()".
- Simlarly, what are the possible errors for the "signal()" syscall?
(Help me!)
$ man -s2 kill
On my GNU/Linux computer, I can notice three errors:
On my GNU/Linux computer, I can notice three errors:
#include <stdio.h> #include <sys/types.h> #include <signal.h> #include <errno.h> int main(int arg, char** argv) { // We assume here that "9278" is a valid process id if (kill(9278, 192) == -1) { printf("Invalid kill. errno=%d\n", errno); if (errno == EINVAL) { printf("Success for error EINVAL\n"); } } }