Ajout du fichier cronbis.c
This commit is contained in:
parent
ed687937a7
commit
e96c375f26
42
C_Language/cronbis.c
Normal file
42
C_Language/cronbis.c
Normal 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user