Homework #1Assigned: January 12
Due: January 21, 3:00pm, in class
- (1 point each) Problems 1-4 are accessed and
submitted through GOAL; see
Gradiance
student guide for more information.
- (14 points) Write a C (not C++) program
/home/<logname>/homeworks/hw1/words.c
to read a stream of text from standard input until
EOF and write to standard output only the
total number of words read and the average number
of words per line, in that order, where a word is
defined as any string of characters except
whitespace. For instance,
$ hostname
cpsrhc1.cps.udayton.edu
$ ./a.out < /etc/mime.types
801 1.55
Keep your program to approximately 30 lines
and submit a listing of it in class.
- (14 points) Write a C (not C++) program
/home/<logname>/homeworks/hw1/ping.c
to synchronize 20 processes to print the following
(of course, with different process and parent
process ids):
PPID: 310, PID: 497, ping
PPID: 497, PID: 498, pong
PPID: 498, PID: 499, ping
PPID: 499, PID: 500, pong
PPID: 500, PID: 501, ping
PPID: 501, PID: 502, pong
PPID: 502, PID: 503, ping
PPID: 503, PID: 504, pong
PPID: 504, PID: 505, ping
PPID: 505, PID: 506, pong
PPID: 506, PID: 507, ping
PPID: 507, PID: 508, pong
PPID: 508, PID: 509, ping
PPID: 509, PID: 510, pong
PPID: 510, PID: 511, ping
PPID: 511, PID: 512, pong
PPID: 512, PID: 513, ping
PPID: 513, PID: 514, pong
PPID: 514, PID: 515, ping
PPID: 515, PID: 516, pong
The first process must print ping and
its child must print pong, then the
child of that child must print ping and
its child must print pong, and so
on.
Keep your program to approximately 25 lines
and submit a listing of it in class.
|