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
5b5248e7
Commit
5b5248e7
authored
14 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
- Some final changes to OS ass3.
parent
cfbf4096
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
+40
-41
40 additions, 41 deletions
os/ass3/fishbones.c
with
40 additions
and
41 deletions
os/ass3/fishbones.c
+
40
−
41
View file @
5b5248e7
...
...
@@ -37,17 +37,17 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
{
/* Error while reading from the pipe, exit */
fprintf
(
log1
,
"Child %d read from pipe with error "
"and exited
\n
"
,
myNumber
);
"and exited
\n
"
,
myNumber
);
fprintf
(
log2
,
"Child %d read from pipe with error "
"and exited
\n
"
,
myNumber
);
"and exited
\n
"
,
myNumber
);
fprintf
(
log3
,
"Child %d read from pipe with error "
"and exited
\n
"
,
myNumber
);
"and exited
\n
"
,
myNumber
);
fclose
(
log1
);
fclose
(
log2
);
fclose
(
log3
);
exit
(
1
);
}
/* Character read successfully, process it */
fprintf
(
log1
,
"Child %d read character %x: '%c'
\n
"
,
myNumber
,
c
,
c
);
fprintf
(
log2
,
"Child %d read character %x: '%c'
\n
"
,
myNumber
,
c
,
c
);
...
...
@@ -55,35 +55,35 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
if
(
c
==
'P'
)
{
/* Decrease antidote level or exit the process */
if
(
!
antidote
)
{
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
);
break
;
}
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
);
}
/* Decrease antidote level or exit the process */
if
(
!
antidote
)
{
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
);
break
;
}
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
);
}
}
else
if
(
c
==
'A'
)
{
/* Increase antidote level */
antidote
++
;
fprintf
(
log1
,
"Child %d finds antidote (now has %d)
\n
"
,
myNumber
,
antidote
);
fprintf
(
log2
,
"Child %d finds antidote (now has %d)
\n
"
,
myNumber
,
antidote
);
fprintf
(
log3
,
"Child %d finds antidote (now has %d)
\n
"
,
myNumber
,
antidote
);
/* Increase antidote level */
antidote
++
;
fprintf
(
log1
,
"Child %d finds antidote (now has %d)
\n
"
,
myNumber
,
antidote
);
fprintf
(
log2
,
"Child %d finds antidote (now has %d)
\n
"
,
myNumber
,
antidote
);
fprintf
(
log3
,
"Child %d finds antidote (now has %d)
\n
"
,
myNumber
,
antidote
);
}
}
while
(
c
!=
'\0'
);
...
...
@@ -103,7 +103,7 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
void
signal_handler
(
int
signum
)
{
char
*
sig
=
"TERM"
;
char
*
sig
=
"TERM"
;
pid_t
pid
;
switch
(
signum
)
...
...
@@ -129,8 +129,6 @@ signal_handler(int signum)
default:
puts
(
"This handler is unapplicable for this type of signal"
);
}
errno
=
0
;
}
/*
...
...
@@ -147,13 +145,9 @@ main(int argc, char * argv[])
/* Save parent process id for signal handler */
parent_pid
=
getpid
();
/* Open one buffered and one unbuffered log */
printf
(
"argc: %d
\n
"
,
argc
);
log1
=
fopen
(
"child.log1"
,
"wt+"
);
log2
=
fopen
(
"child.log2"
,
"wt+"
);
setvbuf
(
log2
,
NULL
,
_IONBF
,
BUFSIZ
);
printf
(
"argc: %d
\n
"
,
argc
);
/* Create pipe, exit with error on failure */
if
(
pipe
(
pipe_id
)
)
{
...
...
@@ -164,13 +158,18 @@ main(int argc, char * argv[])
/* Bind signal handlers */
if
(
sigaction
(
SIGINT
,
&
action
,
NULL
)
+
sigaction
(
SIGTERM
,
&
action
,
NULL
)
+
sigaction
(
SIGCHLD
,
&
action
,
NULL
)
<
0
)
||
sigaction
(
SIGTERM
,
&
action
,
NULL
)
||
sigaction
(
SIGCHLD
,
&
action
,
NULL
)
)
{
perror
(
"An error occured while binding the signal handlers
\n
"
);
exit
(
1
);
}
/* Open one buffered and one unbuffered log */
log1
=
fopen
(
"child.log1"
,
"wt+"
);
log2
=
fopen
(
"child.log2"
,
"wt+"
);
setvbuf
(
log2
,
NULL
,
_IONBF
,
BUFSIZ
);
/* Keep reading input */
while
(
(
c
=
getchar
())
)
{
...
...
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