tutorial slide
[tsh-lab.git] / mysplit.c
blob9ac016e541556e224c315ec5e41e8d8beccfbb21
1 /*
2 * mysplit.c - Another handy routine for testing your tiny shell
3 *
4 * usage: mysplit <n>
5 * Fork a child that spins for <n> seconds in 1-second chunks.
6 */
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <stdlib.h>
10 #include <sys/types.h>
11 #include <sys/wait.h>
12 #include <signal.h>
14 int main(int argc, char **argv)
16 int i, secs;
18 if (argc != 2) {
19 fprintf(stderr, "Usage: %s <n>\n", argv[0]);
20 exit(0);
22 secs = atoi(argv[1]);
25 if (fork() == 0) { /* child */
26 for (i=0; i < secs; i++)
27 sleep(1);
28 exit(0);
31 /* parent waits for child to terminate */
32 wait(NULL);
34 exit(0);