Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
criu
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhul
criu
Commits
8ea8d4ee
Commit
8ea8d4ee
authored
Nov 22, 2011
by
Cyrill Gorcunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: pipes -- Add a second pipe
Signed-off-by:
Cyrill Gorcunov
<
gorcunov@gmail.com
>
parent
46083e9e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
8 deletions
+31
-8
test-pipe-async.c
test/test-pipe-async.c
+31
-8
No files found.
test/test-pipe-async.c
View file @
8ea8d4ee
...
@@ -16,13 +16,14 @@ static void *map;
...
@@ -16,13 +16,14 @@ static void *map;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
pipefd
[
2
];
int
pipefd1
[
2
];
int
pipefd2
[
2
];
pid_t
pid
;
pid_t
pid
;
printf
(
"%s pid %d
\n
"
,
argv
[
0
],
getpid
());
printf
(
"%s pid %d
\n
"
,
argv
[
0
],
getpid
());
if
(
pipe
(
pipefd
))
{
if
(
pipe
(
pipefd
1
))
{
perror
(
"Can't create pipe"
);
perror
(
"Can't create pipe
1
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -32,15 +33,37 @@ int main(int argc, char *argv[])
...
@@ -32,15 +33,37 @@ int main(int argc, char *argv[])
return
1
;
return
1
;
}
else
if
(
pid
==
0
)
{
}
else
if
(
pid
==
0
)
{
long
buf
;
long
buf
;
while
(
read
(
pipefd
[
0
],
&
buf
,
sizeof
(
buf
))
>
0
)
{
printf
(
"pipe-r: %08lx
\n
"
,
buf
);
if
(
pipe
(
pipefd2
))
{
sleep
(
2
);
perror
(
"Can't create pipe2"
);
return
-
1
;
}
pid
=
fork
();
if
(
pid
==
-
1
)
{
printf
(
"fork failed
\n
"
);
return
1
;
}
else
if
(
pid
==
0
)
{
while
(
1
)
{
long
buf
;
read
(
pipefd1
[
0
],
&
buf
,
sizeof
(
buf
));
printf
(
"pipe2-r: %08lx
\n
"
,
buf
);
sleep
(
1
);
}
}
while
(
1
)
{
read
(
pipefd1
[
0
],
&
buf
,
sizeof
(
buf
));
printf
(
"pipe1-r: %08lx
\n
"
,
buf
);
printf
(
"pipe2-w: %08lx
\n
"
,
buf
);
write
(
pipefd2
[
1
],
&
buf
,
sizeof
(
buf
));
sleep
(
1
);
}
}
}
else
{
}
else
{
long
buf
=
0
;
long
buf
=
0
;
while
(
1
)
{
while
(
1
)
{
printf
(
"pipe-w: %08lx
\n
"
,
buf
);
printf
(
"pipe
1
-w: %08lx
\n
"
,
buf
);
write
(
pipefd
[
1
],
&
buf
,
sizeof
(
buf
));
write
(
pipefd
1
[
1
],
&
buf
,
sizeof
(
buf
));
sleep
(
1
);
sleep
(
1
);
buf
++
;
buf
++
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment