| |||||
FORUM HardWare.fr

Programmation

[C/C++/UNIX] Comment détecter qu'une instance d'un pgm est déjà lancé| Dernière réponse | |
|---|---|
| Sujet : [C/C++/UNIX] Comment détecter qu'une instance d'un pgm est déjà lancé | |
| robripper | Bon, j'ai une petite solution ici, c peut être pas trop trop élégant mais ça fonctionne :heink: :D #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> static char pgm_name[256]; static void sig_int(int signo) { char cmd[255]; sprintf(cmd, "chmod +x %s", pgm_name); system(cmd); exit(0); } main(int argc, char *argv[]) { char cmd[255]; strcpy(pgm_name, argv[0]); sprintf(cmd, "chmod -x %s", pgm_name); system(cmd); signal(SIGINT, sig_int); while(1) { printf("%s toujours vivant!\n", argv[0]); sleep(1); } } |
| Vue Rapide de la discussion |
|---|