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
a3543b9d
Commit
a3543b9d
authored
14 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
- Added some more comment to OS ass3.
parent
e2b4672d
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
+16
-14
16 additions, 14 deletions
os/ass3/fishbones.c
with
16 additions
and
14 deletions
os/ass3/fishbones.c
+
16
−
14
View file @
a3543b9d
...
...
@@ -6,6 +6,9 @@
#include
<errno.h>
#include
<signal.h>
/*
* Read from pipe (child processes only).
*/
static
void
gup
(
FILE
*
log1
,
FILE
*
log2
,
int
pipe_id
[
2
],
int
myNumber
)
{
FILE
*
log3
;
...
...
@@ -94,6 +97,9 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
exit
(
0
);
}
/*
* Signal handler for SIGINT, SIGTERM and SIGCHLD.
*/
void
signal_handler
(
int
signum
)
{
...
...
@@ -111,6 +117,9 @@ signal_handler(int signum)
}
}
/*
* Main funtion, initiates the program.
*/
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -125,18 +134,17 @@ main(int argc, char * argv[])
log2
=
fopen
(
"child.log2"
,
"wt+"
);
setvbuf
(
log2
,
NULL
,
_IONBF
,
BUFSIZ
);
/* So log1 is buffered; log2 is not buffered, which means that output
to log2 is written immediately. */
*
to log2 is written immediately. */
/* create the pipe somewhere around here (why?).
remember to test for success!! */
if
(
pipe
(
pipe_id
)
)
/* Create pipe, exit with error on failure */
if
(
pipe
(
pipe_id
)
)
{
fprintf
(
stderr
,
"Error %d occured while creating the pipe
\n
"
,
errno
);
exit
(
1
);
}
/* Bind signal handlers */
action
.
sa_handler
=
signal_handler
;
if
(
sigaction
(
SIGINT
,
&
action
,
NULL
)
<
0
...
...
@@ -147,15 +155,9 @@ main(int argc, char * argv[])
exit
(
1
);
}
/* Keep reading input */
while
(
(
c
=
getchar
())
)
{
/* You can now choose to use only the first character in the
string (inString[0]), or the entire string (how would you test
that?).
Anyway, read a character, echo it to both log files
and write it into the pipe (unless you have to call fork)
*/
/* Ignore newlines and spaces */
if
(
c
==
'\n'
||
c
==
32
)
{
...
...
@@ -180,7 +182,7 @@ main(int argc, char * argv[])
exit
(
1
);
}
/* Wait for child process to 'eat poison' */
/* Wait for child process to 'eat
the
poison' */
if
(
c
==
'P'
)
wait
(
NULL
);
}
...
...
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