Ubuntu Pastebin

Paste from mkelogg at Thu, 16 Mar 2017 23:35:25 +0000

Download as text
 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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(void)
{
    int pfds[2];
    int pfds2[2];	
    pipe(pfds);
    pipe(pfds2);
if (!fork()){

    if (!fork()) {
        close(1);       /* close normal stdout */
        dup(pfds[1]);   /* make stdout same as pfds[1] */
        close(pfds[0]); /* we don't need this closes up input side of pipe*/
        execlp("cat", "cat","/etc/passwd", NULL);
    } else {
	
        close(0);       /* close normal stdin */
        dup(pfds[0]);   /* make stdin same as pfds[0] */
        close(pfds[1]); /* we don't need this closes up output side of pipe*/
        execlp("cut", "cut", "-f1","-d:", NULL);

    }

}else{
	close(0);       /* close normal stdin */	
        dup(pfds2[0]);   /* make stdin same as pfds[0] */
        close(pfds2[1]); /* we don't need this closes up output side of pipe*/
        execlp("sort", "sort", NULL);
}

return 0;
}
Download as text