Ajout du fichier cronbis.c

master
Philippe Pittoli 2011-03-21 12:23:55 +01:00
parent ed687937a7
commit e96c375f26
1 changed files with 42 additions and 0 deletions

42
C_Language/cronbis.c Normal file
View File

@ -0,0 +1,42 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
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);
}