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
b4298d2e
Commit
b4298d2e
authored
14 years ago
by
Sander Mathijs van Veen
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
ssh://vo20.nl/git/uva
Conflicts: os/ass3/fishbones.c
parents
613b0b52
5b5248e7
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/fishbones.c
+11
-14
11 additions, 14 deletions
os/ass3/fishbones.c
os/ass3/report/report.tex
+67
-4
67 additions, 4 deletions
os/ass3/report/report.tex
with
78 additions
and
18 deletions
os/ass3/fishbones.c
+
11
−
14
View file @
b4298d2e
...
...
@@ -47,7 +47,7 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
fclose
(
log3
);
exit
(
1
);
}
/* Character read successfully, process it */
fprintf
(
log1
,
"Child %d read character %x: '%c'
\n
"
,
myNumber
,
c
,
c
);
fprintf
(
log2
,
"Child %d read character %x: '%c'
\n
"
,
myNumber
,
c
,
c
);
...
...
@@ -85,7 +85,7 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
fprintf
(
log3
,
"Child %d finds antidote (now has %d)
\n
"
,
myNumber
,
antidote
);
}
}
while
(
c
!=
'\0'
);
}
while
(
c
);
/* Close logs and exit normally */
fprintf
(
log1
,
"Child %d normal exit
\n
"
,
myNumber
);
...
...
@@ -103,7 +103,7 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
void
signal_handler
(
int
signum
)
{
char
*
sig
=
"TERM"
;
char
*
sig
=
"TERM"
;
pid_t
pid
;
switch
(
signum
)
...
...
@@ -129,15 +129,13 @@ signal_handler(int signum)
default:
puts
(
"This handler is unapplicable for this type of signal"
);
}
errno
=
0
;
}
/*
* Main funtion, initiates the program.
*/
int
main
(
int
argc
,
char
*
argv
[]
)
main
(
void
)
{
FILE
*
log1
;
FILE
*
log2
;
...
...
@@ -148,12 +146,6 @@ main(int argc, char * argv[])
/* Save parent process id for signal handler */
parent_pid
=
getpid
();
/* Open one buffered and one unbuffered log */
printf
(
"argc: %d
\n
"
,
argc
);
log1
=
fopen
(
"child.log1"
,
"wt+"
);
log2
=
fopen
(
"child.log2"
,
"wt+"
);
setvbuf
(
log2
,
NULL
,
_IONBF
,
BUFSIZ
);
/* Create pipe, exit with error on failure */
if
(
pipe
(
pipe_id
)
)
{
...
...
@@ -164,13 +156,18 @@ main(int argc, char * argv[])
/* Bind signal handlers */
if
(
sigaction
(
SIGINT
,
&
action
,
NULL
)
+
sigaction
(
SIGTERM
,
&
action
,
NULL
)
+
sigaction
(
SIGCHLD
,
&
action
,
NULL
)
<
0
)
||
sigaction
(
SIGTERM
,
&
action
,
NULL
)
||
sigaction
(
SIGCHLD
,
&
action
,
NULL
)
)
{
perror
(
"An error occured while binding the signal handlers
\n
"
);
exit
(
1
);
}
/* Open one buffered and one unbuffered log */
log1
=
fopen
(
"child.log1"
,
"wt+"
);
log2
=
fopen
(
"child.log2"
,
"wt+"
);
setvbuf
(
log2
,
NULL
,
_IONBF
,
BUFSIZ
);
/* Keep reading input */
while
(
(
c
=
getchar
())
)
{
...
...
This diff is collapsed.
Click to expand it.
os/ass3/report/report.tex
+
67
−
4
View file @
b4298d2e
...
...
@@ -185,20 +185,83 @@ niet verder aan bod in dit practicum en wordt daarom niet verder behandeld.
\section
{
De opdracht
}
\subsection
{
Keyboard verwerken
}
Door middel van de C functie
\texttt
{
getchar()
}
binnen een
\emph
{
while
}
-loop
wordt de invoer van de gebruiker uitgelezen. Witregels en spaties (ascii: 32)
worden genegeerd.
\subsection
{
Fork en pipe implementatie
}
Als er een
\texttt
{
f
}
wordt gelezen, weet de bigfish dat er een nieuwe gup dient
te worden aangemaakt; fork() gebruiken en het kindproces gup() laten aanroepen.
\subsection
{
Fork/pipe/wait implementatie
}
\begin{lstlisting}
[numbers=none,backgroundcolor=
\color
{
darkgray
}
]
switch( (child
_
id = fork()) )
{
case -1:
perror("Child could not be created
\n
");
exit(1);
case 0:
/* Child process continues.. */
gup(log1, log2, pipe
_
id, kiddoCount);
break;
default:
/* Parent proces continues.. */
printf("Started child process
%d with id %d\n",
kiddoCount, child
_
id);
}
\end{lstlisting}
\noindent
Door middel van
\texttt
{
pipe()
}
wordt een array van file descriptors
aangemaakt, die wijzen naar het uiteinden van de pipe. Het aanmaken van de pipe
gebeurt voor
\texttt
{
fork()
}
, anders kan er geen data worden verstuurd naar het
kindproces. Dan schrijft het ouderproces het karakter naar de ``voederbak'' met
\texttt
{
write()
}
.
\begin{lstlisting}
[numbers=none,backgroundcolor=
\color
{
darkgray
}
]
if( write(pipe
_
id[1],
&
c, 1) <= 0 )
perror("broken pipe.");
\end{lstlisting}
\noindent
en een van de kindprocessen leest vervolgens uit de pipe met
\texttt
{
read()
}
.
\begin{lstlisting}
[numbers=none,backgroundcolor=
\color
{
darkgray
}
]
if( read(pipe
_
id[0],
&
c, 1) <= 0 )
perror("unable to read from pipe.");
\end{lstlisting}
\noindent
voordat het kindproces leest en het ouderproces schrijft, worden
\texttt
{
pipe
\_
id[1]
}
en respectievelijk
\texttt
{
pipe
\_
id[0]
}
met
\texttt
{
close()
}
afgesloten. De aangemaakte pipe is immers eenrichtingsverkeer.
\subsection
{
Experimenten met logfiles
}
\begin{lstlisting}
[language=bash,numbers=none]
for i in
{
1..6
}
; do ./fish < input
$
i.txt; .
/
view
-
logs.bash; done
\begin{lstlisting}
[language=bash,numbers=none,backgroundcolor=
\color
{
darkgray
}
]
for i in
{
1..6
}
; do ./fish < input
$
i.txt;
\
.
/
view
-
logs.bash; done
\end
{
lstlisting
}
% In de aangeleverde code worden met opzet meerdere verschillende log files
% worden aangemaakt, op verschillende plaatsen/tijdstippen en met verschillende
% eigenschappen. Bestudeer je log files ook steeds goed. Wat komt er in terecht?
% In welke volgorde? Ontbreekt er ook informatie? Probeer de verschillen te
% verklaren (in je verslag).
\subsection
{
Signal verwerking
}
\begin
{
lstlisting
}
[
numbers
=
none,backgroundcolor
=
\color
{
darkgray
}
]
/*
Bind signal handlers
*/
if
(
sigaction
(
SIGINT,
&
action, NULL
)
|| sigaction
(
SIGTERM,
&
action, NULL
)
|| sigaction
(
SIGCHLD,
&
action, NULL
)
)
{
perror
(
"binding the signal handlers failed.
\n
"
)
;
exit
(
1
)
;
}
\end
{
lstlisting
}
% wait() beschrijven.
\pagebreak
\begin
{
appendices
}
...
...
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