tutorial slide
[tsh-lab.git] / mystop.c
blob12eee5f85a1e086e72e1a6437f5e51b9fd13abd0
1 /*
2 * mystop.c - Another handy routine for testing your tiny shell
3 *
4 * usage: mystop <n>
5 * Sleeps for <n> seconds and sends SIGTSTP to itself.
7 */
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <stdlib.h>
11 #include <sys/types.h>
12 #include <sys/wait.h>
13 #include <signal.h>
15 int main(int argc, char **argv)
17 int i, secs;
18 pid_t pid;
20 if (argc != 2) {
21 fprintf(stderr, "Usage: %s <n>\n", argv[0]);
22 exit(0);
24 secs = atoi(argv[1]);
26 for (i=0; i < secs; i++)
27 sleep(1);
29 pid = getpid();
31 if (kill(-pid, SIGTSTP) < 0)
32 fprintf(stderr, "kill (tstp) error");
34 exit(0);