-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6b.c
More file actions
49 lines (42 loc) · 686 Bytes
/
6b.c
File metadata and controls
49 lines (42 loc) · 686 Bytes
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
48
49
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <stdlib.h>
int main(void)
{
int fd[2]; //fd[0] read end, fd[1] write end of a pipe
int wstatus;
char buf[100];
pipe(fd);
int nfds = 2;
fd_set readfs;
struct timeval t;
t.tv_sec = 7;
t.tv_usec = 0;
FD_ZERO(&readfs);
FD_SET(fd[0], &readfs);
int ret = fork();
if(ret == -1)
printf("sdsds");
if(ret == 0)
{
write(fd[1],"anmol",5);
}
else
{
int v = select(nfds,&readfs,NULL,NULL,&t);
if(v == -1)
printf("error");
else if(v)
{
read(fd[0],buf,10);
printf("%s",buf);
printf("Success");
exit(0);
}
else
printf("Time-Out");
}
return 0;
}