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
b4298d2e
Commit
b4298d2e
authored
Nov 07, 2010
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://vo20.nl/git/uva
Conflicts: os/ass3/fishbones.c
parents
613b0b52
5b5248e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
18 deletions
+78
-18
os/ass3/fishbones.c
os/ass3/fishbones.c
+11
-14
os/ass3/report/report.tex
os/ass3/report/report.tex
+67
-4
No files found.
os/ass3/fishbones.c
View file @
b4298d2e
...
@@ -47,7 +47,7 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
...
@@ -47,7 +47,7 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
fclose
(
log3
);
fclose
(
log3
);
exit
(
1
);
exit
(
1
);
}
}
/* Character read successfully, process it */
/* Character read successfully, process it */
fprintf
(
log1
,
"Child %d read character %x: '%c'
\n
"
,
myNumber
,
c
,
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
(
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)
...
@@ -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
"
,
fprintf
(
log3
,
"Child %d finds antidote (now has %d)
\n
"
,
myNumber
,
antidote
);
myNumber
,
antidote
);
}
}
}
while
(
c
!=
'\0'
);
}
while
(
c
);
/* Close logs and exit normally */
/* Close logs and exit normally */
fprintf
(
log1
,
"Child %d normal exit
\n
"
,
myNumber
);
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)
...
@@ -103,7 +103,7 @@ static void gup(FILE * log1, FILE * log2, int pipe_id[2], int myNumber)
void
void
signal_handler
(
int
signum
)
signal_handler
(
int
signum
)
{
{
char
*
sig
=
"TERM"
;
char
*
sig
=
"TERM"
;
pid_t
pid
;
pid_t
pid
;
switch
(
signum
)
switch
(
signum
)
...
@@ -129,15 +129,13 @@ signal_handler(int signum)
...
@@ -129,15 +129,13 @@ signal_handler(int signum)
default:
default:
puts
(
"This handler is unapplicable for this type of signal"
);
puts
(
"This handler is unapplicable for this type of signal"
);
}
}
errno
=
0
;
}
}
/*
/*
* Main funtion, initiates the program.
* Main funtion, initiates the program.
*/
*/
int
int
main
(
int
argc
,
char
*
argv
[]
)
main
(
void
)
{
{
FILE
*
log1
;
FILE
*
log1
;
FILE
*
log2
;
FILE
*
log2
;
...
@@ -148,12 +146,6 @@ main(int argc, char * argv[])
...
@@ -148,12 +146,6 @@ main(int argc, char * argv[])
/* Save parent process id for signal handler */
/* Save parent process id for signal handler */
parent_pid
=
getpid
();
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 */
/* Create pipe, exit with error on failure */
if
(
pipe
(
pipe_id
)
)
if
(
pipe
(
pipe_id
)
)
{
{
...
@@ -164,13 +156,18 @@ main(int argc, char * argv[])
...
@@ -164,13 +156,18 @@ main(int argc, char * argv[])
/* Bind signal handlers */
/* Bind signal handlers */
if
(
sigaction
(
SIGINT
,
&
action
,
NULL
)
if
(
sigaction
(
SIGINT
,
&
action
,
NULL
)
+
sigaction
(
SIGTERM
,
&
action
,
NULL
)
||
sigaction
(
SIGTERM
,
&
action
,
NULL
)
+
sigaction
(
SIGCHLD
,
&
action
,
NULL
)
<
0
)
||
sigaction
(
SIGCHLD
,
&
action
,
NULL
)
)
{
{
perror
(
"An error occured while binding the signal handlers
\n
"
);
perror
(
"An error occured while binding the signal handlers
\n
"
);
exit
(
1
);
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 */
/* Keep reading input */
while
(
(
c
=
getchar
())
)
while
(
(
c
=
getchar
())
)
{
{
...
...
os/ass3/report/report.tex
View file @
b4298d2e
...
@@ -185,20 +185,83 @@ niet verder aan bod in dit practicum en wordt daarom niet verder behandeld.
...
@@ -185,20 +185,83 @@ niet verder aan bod in dit practicum en wordt daarom niet verder behandeld.
\section
{
De opdracht
}
\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
}
\subsection
{
Experimenten met logfiles
}
\begin{lstlisting}
[language=bash,numbers=none]
\begin{lstlisting}
[language=bash,numbers=none,backgroundcolor=
\color
{
darkgray
}
]
for i in
{
1..6
}
; do ./fish < input
$
i.txt; .
/
view
-
logs.bash; done
for i in
{
1..6
}
; do ./fish < input
$
i.txt;
\
.
/
view
-
logs.bash; done
\end
{
lstlisting
}
\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
}
\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
\pagebreak
\begin
{
appendices
}
\begin
{
appendices
}
...
...
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