#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char ** argv) {
int i;
if (argc < 2) {
printf("Usage: %s seconds command arg0 ...\n", argv[0]);
exit(EXIT_FAILURE);
}
int status;
while (1) {
pid_t p = fork();
switch (p) {
case -1:
perror("fork");
exit(EXIT_FAILURE);
case 0:
/*child*/
execvp(argv[1], &argv[1]);
perror("exec");
exit(EXIT_FAILURE);
default:
/*parent*/
while (wait(&status) != p) {
perror("wait");
sleep(1);
}
}
}
return 0;
}