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
0cb7be9e
Commit
0cb7be9e
authored
14 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
- Worked on OS ass3.
parent
02d840a8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
os/ass3/Makefile
+1
-1
1 addition, 1 deletion
os/ass3/Makefile
os/ass3/fishbones.c
+45
-16
45 additions, 16 deletions
os/ass3/fishbones.c
with
46 additions
and
17 deletions
os/ass3/Makefile
+
1
−
1
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
...
...
This diff is collapsed.
Click to expand it.
os/ass3/fishbones.c
+
45
−
16
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'
)
{
...
...
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