some-usable-scripts/c/old/cronbis.c

44 lines
706 B
C
Raw Normal View History

2011-03-21 19:41:40 +01:00
#include <sys/wait.h>
2011-03-21 12:23:55 +01:00
#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);
}