I am trying to run a program in C for x minutes. I need to make the child process go to sleep for that amount of time. Any help would be appreciated. Basically I am trying to understand how fork() and sleep() work. Here is my code snippet
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i = fork();
printf("fork return value = %d\n", i);
printf("this is the time before sleep");
system("date +%a%b%d-%H:%M:%S");
printf("\n");
if (i==0){
sleep(120);
}
system("ps");
printf("this is the time after sleep");
system("date +%a%b%d-%H:%M:%S");
printf("\n");
}
Say thanks to Brian “Beej Jorgensen” Hall