assigned: tuesday, january 29 th, 2002 due date: wednesday, february 13 th, 2002 at 5pm -...

17
• ASSIGNED: Tuesday, January 29 th , 2002 •DUE DATE: Wednesday, February 13 th , 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. Project 1 Project 1

Upload: doris-gibbs

Post on 27-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

• 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.

Project 1Project 1

Page 2: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Unix BasicsUnix 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

Page 3: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Unix BasicsUnix Basics

Command Description Exampleps 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

Page 4: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Minix BasicsMinix Basics

Command Description Exampleminix 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

Page 5: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Minix BasicsMinix Basics

Command Description Exampleminix_cleanup Remove dead Minix processes minix_cleanup

mcc Compile (for Minix) mcc p1.c –o p1

©Mark Conner

Page 6: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 1

Banking/Atm problemGeneral 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.

Page 7: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 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.

Page 8: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 1

Root process– Take command line parameter (# of atms)– Create pipes– Create bank & atms– Wait for all children to exit

Page 9: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 1

Root

Bank

N atms

CORRECT!

Page 10: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 1 Root

Bank and Atms

WRONG!!!

Page 11: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 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.

Page 12: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 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.

Page 13: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1 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.

Page 14: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 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

Page 15: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 1

Programming Style– Modular– Global and local variables– Constants– Readability– Comments, comments, and more comments

Page 16: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 1

Compiling and running file in MinixIn Solaris– mcc project1.c –o project1– minix

In Minix– Login as “root”– sunread project1 > project1– chmod +x project1– project1

Page 17: ASSIGNED: Tuesday, January 29 th, 2002 DUE DATE: Wednesday, February 13 th, 2002 at 5pm - project1.c, project1, and project1.out should be in your ~/cop4600/src/tools

Project 1Project 1

Questions?