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
0cb7be9e
Commit
0cb7be9e
authored
Nov 05, 2010
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Worked on OS ass3.
parent
02d840a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
17 deletions
+46
-17
os/ass3/Makefile
os/ass3/Makefile
+1
-1
os/ass3/fishbones.c
os/ass3/fishbones.c
+45
-16
No files found.
os/ass3/Makefile
View file @
0cb7be9e
PROG
=
fish
CC
=
gcc
CFLAGS
=
-std
=
c
99
-pedantic
-Wall
-Wextra
-O3
CFLAGS
=
-std
=
gnu
99
-pedantic
-Wall
-Wextra
-O3
OFILES
=
fishbones.o
RM
=
rm
-f
...
...
os/ass3/fishbones.c
View file @
0cb7be9e
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
...
...
@@ -45,13 +46,12 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
exit
(
1
);
}
fprintf
(
log1
,
"Child %d read character
'%x'
\n
"
,
myNumber
,
c
);
fprintf
(
log2
,
"Child %d read character
'%x'
\n
"
,
myNumber
,
c
);
fprintf
(
log3
,
"Child %d read character
'%x'
\n
"
,
myNumber
,
c
);
fprintf
(
log1
,
"Child %d read character
%x: '%c'
\n
"
,
myNumber
,
c
,
c
);
fprintf
(
log2
,
"Child %d read character
%x: '%c'
\n
"
,
myNumber
,
c
,
c
);
fprintf
(
log3
,
"Child %d read character
%x: '%c'
\n
"
,
myNumber
,
c
,
c
);
switch
(
c
)
{
case
'P'
:
if
(
c
==
'P'
)
{
fprintf
(
log1
,
"Child %d eats poison..."
,
myNumber
);
fprintf
(
log2
,
"Child %d eats poison..."
,
myNumber
);
fprintf
(
log3
,
"Child %d eats poison..."
,
myNumber
);
...
...
@@ -71,7 +71,9 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
fprintf
(
log3
,
"antidote used
\n
"
);
}
break
;
case
'A'
:
}
else
if
(
c
==
'A'
)
{
antidote
++
;
fprintf
(
log1
,
"Child %d finds antidote (now has %d andidote)
\n
"
,
myNumber
,
antidote
);
...
...
@@ -91,7 +93,22 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
exit
(
0
);
}
#define STRING_LENGTH (512)
void
signal_handler
(
int
action
)
{
switch
(
action
)
{
case
SIGINT
:
break
;
case
SIGTERM
:
break
;
case
SIGCHLD
:
break
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
...
...
@@ -100,6 +117,8 @@ main(int argc, char * argv[])
FILE
*
log2
;
char
c
;
int
kiddoCount
=
0
,
pipe_id
[
2
];
//, i = 1;
struct
sigaction
action
;
printf
(
"argc: %d
\n
"
,
argc
);
log1
=
fopen
(
"child.log1"
,
"wt+"
);
log2
=
fopen
(
"child.log2"
,
"wt+"
);
...
...
@@ -107,15 +126,25 @@ main(int argc, char * argv[])
/* 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!! */
if
(
pipe
(
pipe_id
)
)
{
fprintf
(
stderr
,
"Error %d occured while createing the pipe
\n
"
,
errno
);
exit
(
1
);
}
/* create the pipe somewhere around here (why?).
remember to test for success!! */
}
//action.sa_handler = signal_handler;
//if( sigaction(SIGINT, &action, NULL) < 0
// || sigaction(SIGTERM, &action, NULL) < 0
// || sigaction(SIGCHLD, &action, NULL) < 0 )
//{
// perror("An error occured while binding the signal handlers \n");
// exit(1);
//}
while
(
(
c
=
getchar
())
)
{
/* You can now choose to use only the first character in the
...
...
@@ -131,8 +160,8 @@ main(int argc, char * argv[])
continue
;
}
fprintf
(
log1
,
"
Character %x read
\n
"
,
c
);
fprintf
(
log2
,
"
Character %x read
\n
"
,
c
);
fprintf
(
log1
,
"
Parent read character %x: '%c'
\n
"
,
c
,
c
);
fprintf
(
log2
,
"
Parent read character %x: '%c'
\n
"
,
c
,
c
);
printf
(
"Character '%c' read
\n
"
,
c
);
if
(
c
==
'q'
)
...
...
@@ -141,7 +170,7 @@ main(int argc, char * argv[])
}
else
if
(
c
==
'P'
)
{
wait
();
wait
(
NULL
);
}
else
if
(
c
!=
'f'
)
{
...
...
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