Professional Documents
Culture Documents
Unix Programming For BE VTU Cou - I. A. Dhotre
Unix Programming For BE VTU Cou - I. A. Dhotre
UNIX Programming
Iresh A. Dhotre
M.E. (Information Technology)
Ex-Faculty, Sinhgad College of Engineering
Pune
® ®
TECHNICAL
PUBLICATIONS
SINCE 1993 An Up-Thrust for Knowledge
(i)
UNIX Programming
Subject Code : 18CS56
Published by :
® ®
Amit Residency, Office No.1, 412, Shaniwar Peth,
TECHNICAL Pune - 411030, M.S. INDIA, Ph.: +91-020-24495496/97
PUBLICATIONS
SINCE 1993 An Up-Thrust for Knowledge Email : sales@technicalpublications.org Website : www.technicalpublications.org
Printer :
Yogiraj Printers & Binders
Sr.No. 10/1A,
Ghule Industrial Estate, Nanded Village Road,
Tal. - Haveli, Dist. - Pune - 411041.
ISBN 978-93-90041-52-7
9 789390 041527
VTU 18
File system
Interprocess
communication
Hardware control
Hardware
Computer hardware
level
File mapping
Device
mapping
Framework
for Exec a. out
virtual switch elf
memory
Tape driver
Switch NFS
for Common Vfs
FFS
block Amenities interface
device RFS
Disk
driver
System
Network Framework processes
driver Streams for Time
scheduler sharing
TTY
driver process
Excel sheet
Operating
system
Web
browser
Central
processing
unit
Database
updation
Sorting
program
Unix commands
and libraries
System call
interface
Kernel
Hardware
User written
application
1 st
2 nd
3 rd
Verb Options Arguments 1 Arguments 2 Arguments 3 Arguments N
/ root
cmd
date.C who.C
Directory entry
Name Inode
Inode
r read
– (file) w write
x execute
d (directory)
l (symbolic link)
b (block special file)
c (character special file)
p (named pipe special file)
s (local socket special file)
STDOUT STDIN STDOUT STDIN
n th
Contents
Count
1 Rd-Wrt
Count
1 (local)
Count
1 Write
Inode table
user file
descriptor tables
(proc A) file table inode table
0
1
2
3
Count
4 Count
5 1 (/etc/passwd)
1 Read
Count
1 Rd-Wrt
(proc B)
0
1
2 Count
3 Count
1 (local)
4 1 Read
5
Count
1 Write
Count
1 (private)
Count
1 Read
user file file table
descriptors inode table
0
1
2
3
Count
4 Count
5 2 (/etc/passwd)
1
Count
(procB) 1
0
1
2 Count
3 NULL Count
1 (local)
4 NULL 0
5
Count
1
Count
0 (private)
Count
0
/
usr
src include
sys
inode.h testfile.h
{
}
{
}
{
}
{
}
}
}
_exit
or
_Exit
user
functions exit handler
(d
oe e ll
s n xit ca
return
ot
rn
call
re
tu
_exit tu
re
or rn
) call
_Exit main exit exit exit handler
function (does not return) function return user process
ca
return
) ll
call
xit n re
e t ur tu
e rn
o tr
e sn _exit standard I/O
C start-up do or
( cleanup
routine _Exit
exec
Kernel
environment environment environment
pointer list strings
PATH=:/bin:/usr/bin\0
SHEEL=/bin/bash\0
USER=sar\0
LOGNAME=sar\0
NULL
High adress Command line arguments
and environment variables
Stack
Heap
Initialized to zero by
BSS exec
Initialized data
Read from program file
by exec
Text
Per process
region table Region table
u area
Main memory
Process table
Parent Process
File
U Area Table
Per Process
Region Table Open Files
Parent
Current Directory
Data
Changed Root
Parent
User
Stack
Kernel Stack
Shared
Text
Inode
Table
Child
User
Stack
Kernel Stack
Child Process
wait
The waitpid function doesn't wait for the child that terminates first; it has a
number of options that control which process it waits for.
waitpid
waitpid function lets us wait for one particular process, whereas the wait
function returns the status of any terminated child. We'll return to this feature
when we discuss the popen function.
2. The waitpid f
hp
Is > my_files
my_files
User User
processes processes
Kernel
User User
processes processes
Kernel Kernel
P P
P
Data
P
P
User process User process
or
fd(0) fd(1) fd(0) fd(1)
Pipe
Kernel
Parent Child
Fork
fd(0) fd(1) fd(0) fd(1)
Pipe
Kernel
Parent Child
fd(1) fd(0)
Pipe
Kernel
Parent cmdstring(child)
fp stdout
Parent cmdstring(child)
fp stdin
Parent cmdstring(child)
Pipe1
fp(1) stdin
fd(2) stdout
Pipe2
Prog3
Input Prog1
file
Prog2
Server
Read request
Well-known
FIFO
ts
W
es
rit
qu
e
re
re
qu
e
rit
es
W
ts
Client Client
Struct msgqid_ds
Receivers Senders
Messages New
read from msg msg msg messages
head added at
tail
A message queue
Message record
Message table
P semaphore operation
Only a single thread
of execution can
enter the CS at any
one time
V semaphore operation
Semaphore set
Semaphore table
Shared region
Process B
Kernel
Process table
Struct shmid_ds
High address Command-line arguments
and environment variables
Stack 0xbffff9e4
0x4017a6a0
Shared memory Shared memory of 100000 bytes
0x40162000
Heap 0x0806c368
Malloc of 100000 bytes
0x08053cc8
0x08053cc0
Uninitialized data Array F of 40000 bytes
(bss) 0x0804a080
Shared memory
Text
Low address
User process User process
or
fd[0] fd[1] fd[0] fd[1]
Stream pipe
Kernel
stdin
fd[0] fd[1]
stdout
Parent Child(coprocess)
User process
fd[0] fd[1]
Kernel
Process table entry
fd File
flags pointer
fd 0 :
fd 1 :
fd 2 : File table
fd 3 :
File status flags
Current file offset v-node table
v-node pointer v-node
information
i-node
Process table entry information
current file size
fd file
flags pointer
fd 0 :
fd 1 :
fd 2 :
fd 3 :
fd 4 :
User process
fd[0] fd[1]
connld
Client Server
connld
Kernel
Kernel process Kernel region
table A process table
Stack
U area
written to file or
to logged-in users or
sent to another host
user
process
syslog
UDP
port 514
Kernel
routines
kernel
TCP/IP network
(As per 2018 Pattern)