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 #include ... pid_t getpid(void);

This function returns the process ID of the calling process.

This is what I've done:

#include #include #include #include #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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!