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
a3543b9d
Commit
a3543b9d
authored
Nov 07, 2010
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Added some more comment to OS ass3.
parent
e2b4672d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
os/ass3/fishbones.c
os/ass3/fishbones.c
+16
-14
No files found.
os/ass3/fishbones.c
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,11 +134,9 @@ 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. */
/* create the pipe somewhere around here (why?).
remember to test for success!! */
* to log2 is written immediately. */
/* Create pipe, exit with error on failure */
if
(
pipe
(
pipe_id
)
)
{
fprintf
(
stderr
,
"Error %d occured while creating the pipe
\n
"
,
...
...
@@ -137,6 +144,7 @@ main(int argc, char * argv[])
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
);
}
...
...
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