Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
uva
Commits
8471c08b
Commit
8471c08b
authored
14 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
- Changed 'child_id' to 'getpid()' at gup() call in child process, now it works :).
parent
5fb9c53e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
os/ass3/fishbones.c
+10
-15
10 additions, 15 deletions
os/ass3/fishbones.c
with
10 additions
and
15 deletions
os/ass3/fishbones.c
+
10
−
15
View file @
8471c08b
...
...
@@ -52,24 +52,18 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
if
(
c
==
'P'
)
{
fprintf
(
log1
,
"Child %d eats poison..."
,
myNumber
);
fprintf
(
log2
,
"Child %d eats poison..."
,
myNumber
);
fprintf
(
log3
,
"Child %d eats poison..."
,
myNumber
);
if
(
!
antidote
)
{
fprintf
(
log1
,
"no antidote, child will exit
\n
"
);
fprintf
(
log2
,
"no antidote, child will exit
\n
"
);
fprintf
(
log3
,
"no antidote, child will exit
\n
"
);
break
;
fprintf
(
log1
,
"Child %d has no antidote for poison and will exit
\n
"
,
myNumber
);
fprintf
(
log2
,
"Child %d has no antidote for poison and will exit
\n
"
,
myNumber
);
fprintf
(
log3
,
"Child %d has no antidote for poison and will exit
\n
"
,
myNumber
);
}
else
{
antidote
--
;
fprintf
(
log1
,
"antidote used (%d left)
\n
"
,
antidote
);
fprintf
(
log2
,
"antidote used (%d left)
\n
"
,
antidote
);
fprintf
(
log3
,
"antidote used (%d left)
\n
"
,
antidote
);
break
;
fprintf
(
log1
,
"Child %d uses antidote for poison (%d left)
\n
"
,
myNumber
,
antidote
);
fprintf
(
log2
,
"Child %d uses antidote for poison (%d left)
\n
"
,
myNumber
,
antidote
);
fprintf
(
log3
,
"Child %d uses antidote for poison (%d left)
\n
"
,
myNumber
,
antidote
);
}
}
else
if
(
c
==
'A'
)
...
...
@@ -188,16 +182,17 @@ main(int argc, char * argv[])
/* When you fork, be sure to print the process id of the child
(if the fork succeeds) and an error message otherwise */
switch
(
(
child_id
=
fork
()
)
)
switch
(
fork
()
)
{
case
-
1
:
perror
(
"Child could not be created
\n
"
);
exit
(
1
);
case
0
:
gup
(
log1
,
log2
,
pipe_id
,
child_id
);
gup
(
log1
,
log2
,
pipe_id
,
getpid
()
);
break
;
default:
puts
(
"Parent process continuing..."
);
fputs
(
"Parent process continuing...
\n
"
,
log1
);
fputs
(
"Parent process continuing...
\n
"
,
log2
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment