Transcript Project 1
Project 1
• ASSIGNED: Tuesday, January 29th, 2002
•DUE DATE: Wednesday, February 13th, 2002 at 5pm
- project1.c, project1, and project1.out should be in
your ~/cop4600/src/tools directory
- Hand in your report to Prof. Davis in class on
Thursday
- DO NOT touch your files after 5pm. We will check
the timestamp. We will send you an email when it is
safe to access your files again.
Unix Basics
Command
Description
Example
cd
Change directory
cd ~/cop4600
ls
List directory
ls -la
mkdir
Make directory
mkdir backup
rm
Remove file
rm *.c
rmdir
Remove directory
rmdir backup
man
Online manual (help)
man ls
chmod
Change mode (access rights)
chmod 750 *
grep
Search for text in file
grep printf *.c
find
Search for files
find ./ -name “my.c”
©Mark Conner
Unix Basics
Command
Description
Example
ps
Process status (list)
ps –u $USER
kill
Terminate process
kill –9 3291
pwd
Print working directory
pwd
mv
Move (or rename) file/directory
mv p1.c project1.c
cp
Copy file
cp p1.c p1.bak
more
Display text file a page at a time
more project1.c
pico
Simple text editor
pico +20 project1.c
emacs
Advanced (graphical) text editor
emacs project1.c
diff
Compare files
diff p1.c project1.c
©Mark Conner
Minix Basics
Command
Description
Example
minix
Start Minix operating system
minix
sunread
Read file from Solaris OS
sunread p1 > p1
chmod
Change mode (permissions)
chmod +x p1
halt
Shutdown (exit) Minix
halt
minix_setup
Create Minix files/directories
minix_setup
minix_DESTROY
Remove Minix files/dirs
minix_DESTROY
minix_backup
Backup Minix files
minix_backup
minix_diff
Compare Minix to original
minix_diff > report
mlogin
Open another Minix window
mlogin $USER
©Mark Conner
Minix Basics
Command
Description
Example
minix_cleanup
Remove dead Minix processes
minix_cleanup
mcc
Compile (for Minix)
mcc p1.c –o p1
©Mark Conner
Project 1
Banking/Atm problem
General Idea
– Each atm process reads an account number and
value from a file and sends this info to the bank
process
– The bank process gets the info and makes the
changes in the appropriate account.
– This continues until the entire files have been
read by the atms.
Project 1
There are three kinds of processes
– 1 root
– 1 bank
– N atms (0 < N < 7)
There are also N pipes, 1 for each atm to
communicate to the bank.
Project 1
Root process
– Take command line parameter (# of atms)
– Create pipes
– Create bank & atms
– Wait for all children to exit
Project 1
CORRECT!
Root
Bank
N atms
Project 1
WRONG!!!
Bank and Atms
Root
Project 1
Atms
– Open from appropriate file (atm0 uses atm0.txt, atm1
–
–
–
–
uses atm1.txt, etc).
Get account number and transaction amount from file.
Send transaction to bank
Repeat until EOF returned, then send a transaction with
account number –1 to bank and exit
Hint: It might be useful to use fopen() and fscanf() to
open and get the info from the file.
Project 1
Bank
– Check all pipes in order to see if empty or not.
– If not empty, read transaction from pipe and
update appropriate account balance.
– Repeat until all –1 account numbers have been
received then exit.
Project 1
A few things to note:
– The bank & atm processes are executing in
pseudoparallel.
– Read man pages on minix system calls
type “man fork” or “man –s2 fork”
– Read Minix User Guide on web page.
Explains how to compile, sunread, and run a file in
Minix.
Project 1
Requirements
– All processes must close both ends of all
unused pipes
– Print all activities
– Error Checking
Command line parameter
System calls
C library calls
Project 1
Programming Style
– Modular
– Global and local variables
– Constants
– Readability
– Comments, comments, and more comments
Project 1
Compiling and running file in Minix
In Solaris
– mcc project1.c –o project1
– minix
In Minix
– Login as “root”
– sunread project1 > project1
– chmod +x project1
– project1
Project 1
Questions?