diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-23 16:52:27 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-23 16:52:27 +0000 |
| commit | feab4e39d18f97bf1e3365290204a4195d15f2cd (patch) | |
| tree | 8f1d53c2b2c392e777e5af726abb32a1ee2d27a7 /shlab-handout/myint.c | |
| parent | 9cdeda34930cba606725ce1497b72e006e1b1c54 (diff) | |
| parent | 1ffed57168ffaa8bec0dfda56b4b0b8dc957b11a (diff) | |
Merge tiny-shell history into shlab-handout directory
Diffstat (limited to 'shlab-handout/myint.c')
| -rw-r--r-- | shlab-handout/myint.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/shlab-handout/myint.c b/shlab-handout/myint.c new file mode 100644 index 0000000..ea5bee1 --- /dev/null +++ b/shlab-handout/myint.c @@ -0,0 +1,36 @@ +/* + * myint.c - Another handy routine for testing your tiny shell + * + * usage: myint <n> + * Sleeps for <n> seconds and sends SIGINT to itself. + * + */ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <signal.h> + +int main(int argc, char **argv) +{ + int i, secs; + pid_t pid; + + if (argc != 2) { + fprintf(stderr, "Usage: %s <n>\n", argv[0]); + exit(0); + } + secs = atoi(argv[1]); + + for (i=0; i < secs; i++) + sleep(1); + + pid = getpid(); + + if (kill(pid, SIGINT) < 0) + fprintf(stderr, "kill (int) error"); + + exit(0); + +} |
