Codes
1. Seconds to Ticks Conversion
#include "kernel/types.h"
#include "user/user.h"
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Error: Missing argument\n");
exit(1);
}
int seconds = atoi(argv[1]);
int ticks = seconds * 10; // Assume 10 ticks = 1s
pause(ticks);
exit(0);
}2. Strict Argument Validation
#include "kernel/types.h"
#include "user/user.h"
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(2, "Usage: sleep [ticks]\n");
exit(1);
}
pause(atoi(argv[1]));
exit(0);
}3. Ticks Countdown
4. Positive Integer Validation
5. Sleep with Custom Wake Message
6. Duration Verification with uptime()
uptime()7. Iterative Loop of pause(1)
pause(1)8. Default Sleep Duration
9. Periodic Sleep (Interval and Count)
10. Process Identification
Last updated