École Supérieure des Sciences et de la Technologie de Hammam Sousse
TP : Système D’exploitation 2 Durée : 1h30 / Classe : LI1
Enseignant : Ben Khlifa Hamza Année universitaire : 2025-2026
💻Correction TP6: Communication
Inter-Processus (Signaux)
✅ Exercice 1 : Ignorer SIGINT (Ctrl+C)🧪
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
int main() {
signal(SIGINT, SIG_IGN); // Ignorer Ctrl+C
while (1) {
printf("Toujours vivant !\n");
sleep(1);
}
return 0;
}
✅fonction 🧠
Exercice 2 : Gérer SIGUSR1 avec une
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
void mon_handler(int sig) {
printf("Signal %d reçu ! Action spéciale exécutée !\n", sig);
}
int main() {
signal(SIGUSR1, mon_handler);
printf("PID = %d\n", getpid()); // Pour pouvoir envoyer un signal avec
kill
1/5
, École Supérieure des Sciences et de la Technologie de Hammam Sousse
TP : Système D’exploitation 2 Durée : 1h30 / Classe : LI1
Enseignant : Ben Khlifa Hamza Année universitaire : 2025-2026
while (1) {
printf("Attente de signal...\n");
sleep(2);
}
return 0;
}
🔧 Test :
kill -USR1 <PID>
✅SIGKILL 🧑🔧
Exercice 3 : Terminer un processus avec
#include <stdio.h>
#include <unistd.h>
int main() {
printf("PID = %d\n", getpid());
while (1) {
printf("Je suis invincible ? Essayez...\n");
sleep(2);
}
return 0;
🔧 Test :
kill -KILL <PID>
✅SIGUSR2 🚀
Exercice 4 : Réagir différemment à SIGUSR1 et
#include <signal.h>
#include <stdio.h>
2/5
TP : Système D’exploitation 2 Durée : 1h30 / Classe : LI1
Enseignant : Ben Khlifa Hamza Année universitaire : 2025-2026
💻Correction TP6: Communication
Inter-Processus (Signaux)
✅ Exercice 1 : Ignorer SIGINT (Ctrl+C)🧪
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
int main() {
signal(SIGINT, SIG_IGN); // Ignorer Ctrl+C
while (1) {
printf("Toujours vivant !\n");
sleep(1);
}
return 0;
}
✅fonction 🧠
Exercice 2 : Gérer SIGUSR1 avec une
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
void mon_handler(int sig) {
printf("Signal %d reçu ! Action spéciale exécutée !\n", sig);
}
int main() {
signal(SIGUSR1, mon_handler);
printf("PID = %d\n", getpid()); // Pour pouvoir envoyer un signal avec
kill
1/5
, École Supérieure des Sciences et de la Technologie de Hammam Sousse
TP : Système D’exploitation 2 Durée : 1h30 / Classe : LI1
Enseignant : Ben Khlifa Hamza Année universitaire : 2025-2026
while (1) {
printf("Attente de signal...\n");
sleep(2);
}
return 0;
}
🔧 Test :
kill -USR1 <PID>
✅SIGKILL 🧑🔧
Exercice 3 : Terminer un processus avec
#include <stdio.h>
#include <unistd.h>
int main() {
printf("PID = %d\n", getpid());
while (1) {
printf("Je suis invincible ? Essayez...\n");
sleep(2);
}
return 0;
🔧 Test :
kill -KILL <PID>
✅SIGUSR2 🚀
Exercice 4 : Réagir différemment à SIGUSR1 et
#include <signal.h>
#include <stdio.h>
2/5