1 /*
2 * This program starts processes one and two simultaneously.
3 */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include <errno.h>
10 #include <sys/types.h>
11 #include <sys/wait.h>
12
main(int argc,char ** argv)13 int main(int argc, char **argv)
14 {
15 pid_t pid;
16 char *Prog;
17
18 if (argc != 3) {
19 fprintf(stderr, "Usage: %s <process> <datafile>\n", argv[0]);
20 exit(2);
21 }
22
23 Prog = strrchr(argv[1], '/');
24 Prog++;
25
26 if ((pid = fork()) < 0) {
27 printf("Failed in forking, Errno = %d", errno);
28 exit(2);
29 } else if (pid == 0) { /* child */
30 execl(argv[1], Prog, "0", argv[2], NULL);
31 } else { /* parent */
32 execl(argv[1], Prog, "1", argv[2], NULL);
33 }
34
35 /*if (waitpid(pid, NULL, 0) != pid)
36 printf("Failed in waitpid, Errno = %d", errno);
37 */
38 exit(0);
39 }
40