Question: Write a small program, sleepy , that gets a loop count from the command line: sleepy n where n is the number of seconds for
Write a small program, sleepy, that gets a loop count from the command line:
sleepy n
where n is the number of seconds for which the program should run. Implement this timing by putting a loop n times of sleep(1) - this will put the program to sleep for one second n times before exiting.
In each loop print out the process ID and the loop count so that that particular process can be identified.
The process ID can be obtained from the getpid function:
| #include This function returns the process ID of the calling process. |
This is what I've done:
#include
int main(int argc, char* argv[])
{ int seconds; int i; if(isdigit(argv[i][0])){ seconds = atoi(argv[i]); printf("seconds = %d ", seconds); } int pid = (int) getpid(); int i; for (i = 0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
