Task 1: sleep

  1. Seconds to Ticks Conversion – Modify sleep to accept time in seconds and convert to ticks internally (assume 10 ticks = 1s).

  2. Strict Argument Validation – Require exactly one argument; print a "Usage: sleep [ticks]" error if zero or multiple arguments are provided.

  3. Ticks Countdown – Implement a countdown that prints the remaining ticks every 10 ticks until it hits zero.

  4. Positive Integer Validation – Add a check to ensure the input is a positive integer; print an error if a negative number is entered.

  5. Sleep with Custom Message – Create a version that takes two arguments: sleep [ticks] [message] and prints the message upon waking.

  6. Duration Verification with uptime() – Modify sleep to call uptime() before and after the pause to verify the actual duration.

  7. Iterative pause(1) Loop – Change the program to use a loop of pause(1) calls instead of a single pause(n) call.

  8. Default Sleep Duration – If no argument is provided, default to a sleep of 10 ticks rather than exiting with an error.

  9. Periodic Sleep – Implement a "periodic sleep" that takes two numbers: sleep [interval] [count] to repeat the pause.

  10. Process ID (PID) Logging – Combine sleep with a getpid() call to print "Process [PID] is sleeping..." before the pause.

Last updated