Lab Solution
Assignment Task: sleep (Lab1-w1)
#include "kernel/types.h"
#include "user/user.h"
int main(int argc, char *argv[]) {
// If the user forgets to pass an argument, print an error message[cite: 25].
if (argc < 2) {
fprintf(2, "Error: missing argument for sleep\n");
exit(1);
}
// Convert command-line string argument to integer using atoi[cite: 26].
int ticks = atoi(argv[1]);
// Use the system call "pause"[cite: 27].
pause(ticks);
// Call exit(0) when done[cite: 29].
exit(0);
}Last updated