Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Processes II<br />
! File and Record Locking<br />
UNIX line printer<br />
- Process has to place a job on <strong>the</strong> print queue.<br />
- has to assign a unique sequence number to each job<br />
- job exists long enough for process ID to be reused<br />
- file for each printer contains sequence number<br />
Each process that needs a sequence number<br />
- reads <strong>the</strong> sequence number file<br />
- uses <strong>the</strong> number<br />
- increments <strong>the</strong> number and writes it back<br />
The problem is that in <strong>the</strong> time it takes a single process to execute <strong>the</strong>se three steps, ano<strong>the</strong>r process can perform<br />
<strong>the</strong> same steps. Chaos results.<br />
! Advisory Locking versus Mandatory Locking<br />
Advisory locking means that <strong>the</strong> operating system maintains information about which files have been locked and<br />
by which process. A process can ignore an advisory lock and write to it, if <strong>the</strong> process has adequate permissions.<br />
This is fine for cooperating processes.<br />
Mandatory locking means that <strong>the</strong> operating system check every read and write request to verify that <strong>the</strong> operation<br />
does not interfere <strong>with</strong> a lock held by a process. (System V Release 3 only - turn group-execute bit off and turn<br />
set-group-ID on for file)<br />
! File Locking versus Record Locking<br />
File locking locks an entire file, while record locking allows a process to lock a specified portion of a file (on<br />
UNIX several records are locked this is called range locking).<br />
! O<strong>the</strong>r <strong>Unix</strong> Locking Techniques<br />
1. The link system call fails if <strong>the</strong> name of <strong>the</strong> new link to <strong>the</strong> file already exists.<br />
2. The creat system call fails if <strong>the</strong> file already exists and if <strong>the</strong> caller does not have write permission for <strong>the</strong> file.<br />
3. Newer version of UNIX, support options to open system call that cause it to fail of <strong>the</strong> file already exists.<br />
- techniques 1 & 2 work on any version of UNIX.<br />
- all take longer to execute than actual file locking system calls.<br />
- an ancillary lock file is required.<br />
- remove ancillary lock files after a system crash<br />
- /tmp? cannot create links across file systems.<br />
- technique does not work for superuser.<br />
- instead of waiting one second - process wanting lock should be notified when lock is available.<br />
Simple Client-Server<br />
Example<br />
Pipes<br />
- Pipe in a single process<br />
stdin<br />
filename<br />
file<br />
client IPC<br />
contents stdout contents<br />
or error<br />
or error<br />
message<br />
user process<br />
read fd<br />
write fd<br />
server<br />
file<br />
kernel<br />
pipe<br />
->flow of data-><br />
133