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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started