Commit 4c224831 authored by Sander van Veen's avatar Sander van Veen

Added example input and improved fishbones.

parent 7f7b1fe8
f a b f c d P e g P x x q
......@@ -67,17 +67,16 @@ static void gup(FILE * log1, FILE * log2, int pipefd[2], int cpid)
fclose(log3);
}
#define STRING_LENGTH (512)
#define STRING_LENGTH (512)
int
main(void)
int main(int argc, char ** argv)
{
FILE * log1;
FILE * log2;
char buf;
int kiddoCount = 0;
int kids = 0;
int pipefd[2];
log1 = fopen("child.log1", "wt+");
......@@ -89,8 +88,6 @@ main(void)
// create the pipe somewhere around here (why?).
// remember to test for success!!
printf("while..\n");
if( pipe(pipefd) == -1 )
{
perror("pipe");
......@@ -99,7 +96,6 @@ main(void)
pid_t cpid;
while( (buf = getchar()) )
{
// You can now choose to use only the first character in the
......@@ -109,6 +105,7 @@ main(void)
// and write it into the pipe (unless you have to call fork)
printf("%c", buf);
fflush(stdout);
switch( buf )
{
......@@ -118,7 +115,7 @@ main(void)
case 'f':
kiddoCount++;
kids++;
// When you fork, be sure to print the process id of the child
// (if the fork succeeds) and an error message otherwise
......@@ -134,25 +131,19 @@ main(void)
if( cpid == 0 )
{
// Child reads from pipe u1
gup(log1, log2, pipefd, kiddoCount);
gup(log1, log2, pipefd, kids);
_exit(EXIT_SUCCESS);
}
else
{
/* Parent writes argv[1] to pipe */
/* Parent writes to pipe */
//write(pipefd[1], buf, len);
// Close unused read end
close(pipefd[0]);
//if( write(pipefd[1], argv[1], strlen(argv[1])) == -1 )
//{
// fprintf(stderr, "write error: %s\n", strerror(errno));
// exit(EXIT_FAILURE);
//}
close(pipefd[1]); /* Reader will see EOF */
wait(NULL); /* Wait for child */
exit(EXIT_SUCCESS);
}
......
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