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
8471c08b
Commit
8471c08b
authored
Nov 06, 2010
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Changed 'child_id' to 'getpid()' at gup() call in child process, now it works :).
parent
5fb9c53e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
15 deletions
+10
-15
os/ass3/fishbones.c
os/ass3/fishbones.c
+10
-15
No files found.
os/ass3/fishbones.c
View file @
8471c08b
...
@@ -52,24 +52,18 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
...
@@ -52,24 +52,18 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
if
(
c
==
'P'
)
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
)
if
(
!
antidote
)
{
{
fprintf
(
log1
,
"no antidote, child will exit
\n
"
);
fprintf
(
log1
,
"Child %d has no antidote for poison and will exit
\n
"
,
myNumber
);
fprintf
(
log2
,
"no antidote, child will exit
\n
"
);
fprintf
(
log2
,
"Child %d has no antidote for poison and will exit
\n
"
,
myNumber
);
fprintf
(
log3
,
"no antidote, child will exit
\n
"
);
fprintf
(
log3
,
"Child %d has no antidote for poison and will exit
\n
"
,
myNumber
);
break
;
}
}
else
else
{
{
antidote
--
;
antidote
--
;
fprintf
(
log1
,
"antidote used (%d left)
\n
"
,
antidote
);
fprintf
(
log1
,
"Child %d uses antidote for poison (%d left)
\n
"
,
myNumber
,
antidote
);
fprintf
(
log2
,
"antidote used (%d left)
\n
"
,
antidote
);
fprintf
(
log2
,
"Child %d uses antidote for poison (%d left)
\n
"
,
myNumber
,
antidote
);
fprintf
(
log3
,
"antidote used (%d left)
\n
"
,
antidote
);
fprintf
(
log3
,
"Child %d uses antidote for poison (%d left)
\n
"
,
myNumber
,
antidote
);
break
;
}
}
}
}
else
if
(
c
==
'A'
)
else
if
(
c
==
'A'
)
...
@@ -188,16 +182,17 @@ main(int argc, char * argv[])
...
@@ -188,16 +182,17 @@ main(int argc, char * argv[])
/* When you fork, be sure to print the process id of the child
/* When you fork, be sure to print the process id of the child
(if the fork succeeds) and an error message otherwise */
(if the fork succeeds) and an error message otherwise */
switch
(
(
child_id
=
fork
()
)
)
switch
(
fork
(
)
)
{
{
case
-
1
:
case
-
1
:
perror
(
"Child could not be created
\n
"
);
perror
(
"Child could not be created
\n
"
);
exit
(
1
);
exit
(
1
);
case
0
:
case
0
:
gup
(
log1
,
log2
,
pipe_id
,
child_id
);
gup
(
log1
,
log2
,
pipe_id
,
getpid
()
);
break
;
break
;
default:
default:
puts
(
"Parent process continuing..."
);
fputs
(
"Parent process continuing...
\n
"
,
log1
);
fputs
(
"Parent process continuing...
\n
"
,
log2
);
}
}
}
}
}
}
...
...
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