Commit a3543b9d authored by Taddeüs Kroes's avatar Taddeüs Kroes

- Added some more comment to OS ass3.

parent e2b4672d
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment