-
Notifications
You must be signed in to change notification settings - Fork 1
/
20.c
47 lines (44 loc) · 1.35 KB
/
20.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/******************************************************************
* @author Rajendra Kumar R. Yadav <[email protected]> *
* @date Feb 2020, 21 *
* @file 20.c *
**************************************************************** */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wait.h>
int main(int argc, char *Argv[])
{
char *input[BUFSIZ];
int pfd[2];
if (pipe(pfd) == -1) {
perror("Error [Pipe cann't created] \n");
exit(-1);
}
if (argc < 3) {
fprintf(stderr, "Usage : %s <filename1> <filename2> ...\n", Argv[0]);
exit(-1);
}
int i = 0;
do {
input[i] = Argv[i + 1];
i++;
} while (argc != i);
makeToken(input);
printf("Process ID : %ld, Parent PID : %ld\n", getpid(), getppid());
switch (fork()) {
case -1:
fprintf(stderr, "Error : Child could not created!\n");
exit(-1);
case 0:
printf("Process ID : %ld, Parent PID : %ld\n", getpid(), getppid());
printf("Parent Process!\n");
break;
default:
printf("Process ID : %ld, Parent PID : %ld\n", getpid(), getppid());
break;
}
exit(EXIT_SUCCESS);
}