Task 1: sleep
Seconds to Ticks Conversion – Modify
sleepto accept time in seconds and convert to ticks internally (assume 10 ticks = 1s).Strict Argument Validation – Require exactly one argument; print a "Usage: sleep [ticks]" error if zero or multiple arguments are provided.
Ticks Countdown – Implement a countdown that prints the remaining ticks every 10 ticks until it hits zero.
Positive Integer Validation – Add a check to ensure the input is a positive integer; print an error if a negative number is entered.
Sleep with Custom Message – Create a version that takes two arguments:
sleep [ticks] [message]and prints the message upon waking.Duration Verification with uptime() – Modify
sleepto calluptime()before and after the pause to verify the actual duration.Iterative pause(1) Loop – Change the program to use a loop of
pause(1)calls instead of a singlepause(n)call.Default Sleep Duration – If no argument is provided, default to a sleep of 10 ticks rather than exiting with an error.
Periodic Sleep – Implement a "periodic sleep" that takes two numbers:
sleep [interval] [count]to repeat the pause.Process ID (PID) Logging – Combine
sleepwith agetpid()call to print "Process [PID] is sleeping..." before the pause.
Last updated