From e96c375f2603cf603fa2f4ddbc9de4e58ae8bff1 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 21 Mar 2011 12:23:55 +0100 Subject: [PATCH] Ajout du fichier cronbis.c --- C_Language/cronbis.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 C_Language/cronbis.c diff --git a/C_Language/cronbis.c b/C_Language/cronbis.c new file mode 100644 index 0000000..28f7a8e --- /dev/null +++ b/C_Language/cronbis.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include + +int main( int argc, char **argv) +{ + if(argc < 3) { fprintf(stdout, "Usage : %s NBSEC COMMANDE\n", argv[0]); exit(EXIT_FAILURE); } + + int NBSEC; + NBSEC = atoi(argv[1]); + int pid; + int fd0; + + while(1) + { + if((pid = fork()) == 0) + { + char ** options = malloc(sizeof(char *)*(argc-2)); + + for(int i = 0; i < (argc -2) ; i++) + options[i] = *argv[i+2]; + + + if((fd0 = open("/dev/null", O_RDONLY)) == -1) + { + erreur("Ouverture /dev/null"); + exit(EXIT_FAILURE); + } + close(0); dup(fd0); + + exit(EXIT_SUCCESS); + } + else + { + waitpid(pid); + sleep(NBSEC); + } + } + exit(EXIT_SUCCESS); +} +