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
4b709e57
Commit
4b709e57
authored
Nov 03, 2010
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Added framework to OS ass3.
parent
52da9aab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
0 deletions
+123
-0
os/ass3/Makefile
os/ass3/Makefile
+16
-0
os/ass3/example.in
os/ass3/example.in
+1
-0
os/ass3/fishbones.c
os/ass3/fishbones.c
+106
-0
No files found.
os/ass3/Makefile
0 → 100644
View file @
4b709e57
PROG
=
fish
CC
=
gcc
CFLAGS
=
-std
=
c99
-pedantic
-Wall
-Wextra
-O3
OFILES
=
fishbones.o
RM
=
rm
-f
$(PROG)
:
$(OFILES)
$(CC)
$(CFLAGS)
-o
$@
$(OFILES)
%.o
:
%.c
$(CC)
$(CFLAGS)
-o
$@
-c
$<
clean
:
$(RM)
$(OFILES)
$(PROG)
os/ass3/example.in
0 → 100644
View file @
4b709e57
fabfcdPegPxxq
os/ass3/fishbones.c
0 → 100644
View file @
4b709e57
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
static
void
gup
(
FILE
*
log1
,
FILE
*
log2
,
int
pipe_id
[
2
],
int
myNumber
)
{
FILE
*
log3
;
char
c
;
/* Put any required declarations and initialisations here */
close
(
pipe_id
[
1
]);
/* Report your existence */
fprintf
(
log1
,
"This is child number %d
\n
"
,
myNumber
);
fprintf
(
log2
,
"This is child number %d
\n
"
,
myNumber
);
/* just for sure - open one more log file .... */
log3
=
fopen
(
"child.log3"
,
"wt+"
);
setvbuf
(
log3
,
NULL
,
_IOLBF
,
BUFSIZ
);
/* log3 is line buffered - a line of output is written
immediately on encountering an end-of-line */
fprintf
(
log3
,
"This is child number %d
\n
"
,
myNumber
);
do
{
/* Read 1 character from the pipe into 'c' here.
Be sure to test that you have indeed read a character.
If you get an error (read returns a negative value) or
an end-of-file (read returns zero), end your program
with an 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
);
/* process the character here */
}
while
(
0
);
/* Put a suitable condition here * );*/
fprintf
(
log1
,
"Child %d normal exit
\n
"
,
myNumber
);
fprintf
(
log2
,
"Child %d normal exit
\n
"
,
myNumber
);
fprintf
(
log3
,
"Child %d normal exit
\n
"
,
myNumber
);
fclose
(
log1
);
fclose
(
log2
);
fclose
(
log3
);
exit
(
0
);
}
#define STRING_LENGTH (512)
int
main
(
int
argc
,
char
*
argv
[])
{
FILE
*
log1
;
FILE
*
log2
;
char
inString
[
STRING_LENGTH
];
int
kiddoCount
=
0
,
pipe_id
[
2
],
i
=
1
;
printf
(
"argc: %d
\n
"
,
argc
);
log1
=
fopen
(
"child.log1"
,
"wt+"
);
log2
=
fopen
(
"child.log2"
,
"wt+"
);
setvbuf
(
log2
,
NULL
,
_IONBF
,
BUFSIZ
);
/* 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!! */
while
(
fgets
(
inString
,
STRING_LENGTH
,
stdin
)
)
{
/* You can now choose to use only the first character in the
string (inString[0]), or the entire string (how would you test
that?).
Anyway, read a character, echo it to both log files
and write it into the pipe (unless you have to call fork)
*/
if
(
/* suitable condition */
)
{
/* write to pipe */
}
else
{
pid_t
child_id
;
kiddoCount
++
;
/* When you fork, be sure to print the process id of the child
(if the fork succeeds) and an error message otherwise */
if
(
child_id
=
fork
()
)
{
/* What code should go here ? */
}
else
{
/* What goes here ? */
}
}
}
/* normal end of program */
/* close all open log files */
return
0
;
}
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