Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
4c224831
Commit
4c224831
authored
Oct 15, 2010
by
Sander van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added example input and improved fishbones.
parent
7f7b1fe8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
19 deletions
+11
-19
os/ass3/example.in
os/ass3/example.in
+1
-0
os/ass3/fishbones.c
os/ass3/fishbones.c
+10
-19
No files found.
os/ass3/example.in
0 → 100644
View file @
4c224831
f a b f c d P e g P x x q
os/ass3/fishbones.c
View file @
4c224831
...
...
@@ -67,17 +67,16 @@ static void gup(FILE * log1, FILE * log2, int pipefd[2], int cpid)
fclose
(
log3
);
}
#define STRING_LENGTH
(512)
#define STRING_LENGTH
(512)
int
main
(
void
)
int
main
(
int
argc
,
char
**
argv
)
{
FILE
*
log1
;
FILE
*
log2
;
char
buf
;
int
kid
doCount
=
0
;
int
kid
s
=
0
;
int
pipefd
[
2
];
log1
=
fopen
(
"child.log1"
,
"wt+"
);
...
...
@@ -89,8 +88,6 @@ main(void)
// create the pipe somewhere around here (why?).
// remember to test for success!!
printf
(
"while..
\n
"
);
if
(
pipe
(
pipefd
)
==
-
1
)
{
perror
(
"pipe"
);
...
...
@@ -99,7 +96,6 @@ main(void)
pid_t
cpid
;
while
(
(
buf
=
getchar
())
)
{
// You can now choose to use only the first character in the
...
...
@@ -109,6 +105,7 @@ main(void)
// and write it into the pipe (unless you have to call fork)
printf
(
"%c"
,
buf
);
fflush
(
stdout
);
switch
(
buf
)
{
...
...
@@ -118,7 +115,7 @@ main(void)
case
'f'
:
kid
doCount
++
;
kid
s
++
;
// When you fork, be sure to print the process id of the child
// (if the fork succeeds) and an error message otherwise
...
...
@@ -134,25 +131,19 @@ main(void)
if
(
cpid
==
0
)
{
// Child reads from pipe u1
gup
(
log1
,
log2
,
pipefd
,
kiddoCount
);
gup
(
log1
,
log2
,
pipefd
,
kids
);
_exit
(
EXIT_SUCCESS
);
}
else
{
/* Parent writes argv[1] to pipe */
/* Parent writes to pipe */
//write(pipefd[1], buf, len);
// Close unused read end
close
(
pipefd
[
0
]);
//if( write(pipefd[1], argv[1], strlen(argv[1])) == -1 )
//{
// fprintf(stderr, "write error: %s\n", strerror(errno));
// exit(EXIT_FAILURE);
//}
close
(
pipefd
[
1
]);
/* Reader will see EOF */
wait
(
NULL
);
/* Wait for child */
exit
(
EXIT_SUCCESS
);
}
...
...
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