OS Unit 1
OS Unit 1
systems
UNIT -
1
INTRODUCTION 4
PROCESS MANAGEMENT
NEED for OS
•
Access hardware interfaces
.
•
Protection and security
Definition user
•
allocator , control
resource
program I
°
Memory
.
°
1/0 modules
°
System Bus
C
! L PC :
prog counter
PC MAR Bus instruction
IR : instruction
instruction register
IR MBR instruction MAR: address
memory
!
110 AR
register
Execution 7 data
yo BR
data
MBR :
memory buffer
data register
110 Module i n -
z
yo AR
input-output
:
" '
address
register
(
110 BR input ) output
:
buffer
Buffers
register
COMPUTER SYSTEM ORGANISATION
.
cpucs) and device controllers have access to shared
memory
via a common bus
•
CPUs) and data controllers compete for memory cycles and can run
concurrently
CPU
disk
controller
USB controller graphics 1/0 devices
adapter
memory
local
memory
•
CPU loads data from main
memory to local buffer
°
Device controller sends interrupt to CPU when task is completed
Bootstrap
°
When
system is booted , first to be executed is Bootstrap
program ,
°
Also referred to as firmware
, ,
main etc )
memory
event to occur
↳
interrupt
Interrupt
•
Transfers control to the interrupt service routine ( ISR)
through the
OS
.
is an
interrupt -
driven
program
of saved OS
.
state CPU
by by storing registers and PC onto stack
Type of interrupt
for device ( 1/0 )
polling
-
-
vectored interrupt system aimer )
segment
completion of task
fetoerage structure
hierarchy of memory
°
implemented semiconductor
with
technology
-
-
DRAM
info : capacitor
-
charge on
EEPRO mobile
phones factory installed
ROM
My :
programs
°
,
control unit Aw
decode execute
✓
^
RAM cstore)
fetch
<
°
Hard disk
-
disk surface : tracks , sectors
-
disk controller : interaction
r
•
SSD -
solid state disk
-
faster
flash speed
memory
-
size
caching
o
-
level 1 and level 2
faster for frequent
storage
-
u
access
•
Device driver
-
interface b/w controller and
Kemal
caching
.
information copied from slower to faster , temporarily
structure
yo
user
completion of yo
-
CPU idles until next interrupt given ( wait instruction)
°
After yo starts , control returns to without
user
program
waiting for yo completion
•
device controller transfers data from device directly to main
computer organisation
structure and behaviour of computer system as seen by the user
graphics controller -
run limited no .
of instructions
managed by OS
°
eg
: disk control microprocessor
-
receives
sequence requests from CPU
,
multiple processors)
(
advantages
•
-
increased throughput
economy of scale cheaper than n single processor systems
-
i.
Asymmetric multiprocessing
each processor
assigned a specific task ( boss -
subordinate)
2 .
Symmetric Multiprocessing
each processor performs all tasks
architecture
Symmetric multiprocessor
DUAL CORE DESIGN
°
Multi -
•
Systems containing all chips ; chassis
containing multiple separate
systems
°
Command ( Linux)
Blade servers
°
multiple processor boards , 1/0 boards , networking boards on same
chassis
•
board boots independently and runs its own OS
•
some blade-
server boards are multiprocessor ; multiple independent
multiprocessor systems
I
Clustered systems
CSAN)
Shares storage via storage network
• -
area
→ ,
each
Symmetric clustering multiple nodes running apps monitoring
:
-
other
for
Some clusters
high performance computing CH Pc )
•
are
•
Some have distributed lock manager CDLM) to avoid conflicts over
shared data
clustered
system
single user cannot keep CPU and 110 devices busy at all
times
job to execute
°
One
job selected and executed via job scheduling
°
Reduce CPU idling
OS structure -
Multitasking
Timesharing (multitasking)
•
°
CPU switches jobs frequently that users can
so interact with each
job while it is
running (interactive computing)
•
Response time Cl second
CPU
scheduling if several jobs to at same time
a
run
and out
swapping moves
processes in of memory
•
•
Virtual memory : execution of processes not
completely in memory
Cpu
user 3
user l user 2
Interrupt Driven
°
Hardware interrupt by one of the devices
•
Software interrupt cexeption or trap)
-
software error (divide by O)
for OS service
request
-
infinite
loops processes modifying OS et
-
,
Dual Mode and Multimode Operation
•
User mode and Kemal mode
•
Mode bit provided by hardware
distinguish
-
system call
changes mode to Kemal , return resets it
Timer
•
variable timer implemented by fixed rate clock and counter
•
interrupt occurs when counter reaches 0 ; prevents prog from running
for too
long
Kemal Data structures
(a) Array
•
each element can be accessed directly
main
memory
•
°
multiple bytes → no . of bytes x
items with
.
varying size ?
advantages
°
:
varying size
-
disadvantages
-
retrieval : Ocn) for size n
-
Kemal
algorithms
stacks and
queues
-
e) Stack
e
LIFO
•
OS : stack of function calls
(d) Queue
•
FIFO
°
task scheduling CPU
printer print jobs
°
(e) Trees
°
BST
-
search : och)
•
Balanced BST
search : 0 Clog n)
-
-
red black -
trees
o
Stat ( filename > → YO block ( 4096 etc)
Unix command
.
Key value pairs
:
o
constant search time
(g) Bitmap
•
string of n
binary digits representing status of n items
o
eg
:
bitmap 001011101
1 .
Traditional
.
stand alone
general purpose machine
•
blurred -
internet
servers
eg company
•
:
2 .
Mobile
•
handheld smartphones ,
tablets
GPS ,
gyroscope
•
°
AR
•
IEEE 802 II - wireless cellular data network
,
Distributed
3 .
computing
collection of
separate computers
•
•
TCP/IP
-
LAN
- WAN
-
MAN
Metropolitan
- PAN Personal -
BT
. Network OS
4 .
client-Server
•
servers
respond to client requests
compute server system
-
-
file server
system
5
.
Peer-to-peer
.
P2P : no client and servers
with lookup
-
nodes
registered central table
-
,
6 .
Virtualisatin
° host OS run
guest OS as
application
•
emulation -
source CPU diff from target CPU
leg : PowerPC to
virtual isatin : OS
natively compiled for running guest oses
•
CPU
also natively compiled
°
VMM -
virtual machine
manager
hardware
JVM
bytecode generated is not specific
° -
-
Computing
computing storage service across network
°
, , apps as a
•
Public cloud : via internet for anyone willing to
pay
.
Services
-
SaaS Software
:
as a Service leg : word processor) Aws
←
Paas : Platform Service database server software stack)
as a
leg
-
: -
°
cloud
computing environments composed of traditional oses, vmms
,
cloud
management tools
load balancers spread traffic (servers)
across
apps
-
8 .
Real Time-
Embedded systems
•
most prevalent form of computers
-
real time OS
-
°
real time-
OS : well -
defined time constraints
-
soft real -
time systems ( do not hamper results with small
delay)
-
hard real time -
systems (
hamper results with small delay)
Jewkes
e
OS
provides environment for execution of
programs and services to
and
programs users
OS services
helpful to user :
•
D User Interface
CLI
,
GUI ,
Batch
2)
Program Execution
exit CD →
,
failure cases
3) 1/0 Operations
Cfile device)
a
running program may require yo or
View of OS services
and
OS
Design Implementation
what to do
policy
°
:
mechanism : how to do
flexibility
e
creative task
implementation of oses :
-
earlier , assembly
then system programming langs Algol , PHI
-
-
now C , Ctt
°
mix of languages
-
lowest levels in
assembly
in
-
main body C
-
°
Emulation : run OS on non native
-
hardware
Process concepts
°
OS executes various
programs
-
batch system -
jobs
time shared systems user or tasks
programs
-
- -
-
code or text section
-
current activity -
PC
, processor registers
-
stack -
function parameters ,
grow
local variables ,
return address
data section
global variables
-
-
heap -
program)
local variables
}
segdmaetnat f
size of
program
a
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int x;
5 int y = 15;
6
7 int main(int argc, char *argv[]) {
8 int *values;
9 int i;
10
11 values = (int *) malloc(sizeof(int)*5);
12
13 for (int i = 0; i < 5; ++i) {
14 values[i] = i;
15 }
16 return 0;
17 }
New created
process being
°
:
instructions executed
Running being
•
:
processor
:
shunted
Ctrl z : into
background suspended
. -
;
Ctrl -
e : abort
process O→ abort
"°
.
↳
O →
bring to foreground
Ctrl
completed
-
c
Ctrl -
z
assigns to CPU
Process control Block ( PCB)
Every process has a PCB ; info associated with each process task
control block)
•
Pc : next instruction
CPU
registers contents of centric registers
process
•
: -
process
time limits
process ,
linux : ps -
aux works
←
O
CPO switch from to
process process
multiprogramming
.
context
switching
.
moved to ready
queue
assign to Cpu
Process Scheduling
maintains
scheduling queues of processes emigrate among queues)
•
queue : processes
Ready queue : set of in
memory , ready and waiting to execute
-
processes
-
linked list
of PCBs
Process scheduling
device queue
←
round
← robin
Schedulers
°
Short term schedulers ( CPU schedulers ) selects next to be
process
- :
(from
executed and assigns it to CPU
ready queue)
invoked Cms)
frequently
-
sometimes scheduler
the
only
-
should
Long term scheduler (
job scheduler) : selects which be
•
process
-
invoked
infrequently Cs min)
-
degree of multiprogramming
-
decrease
bring into
memory from disk continue in
to
swap
-
swapping
-
so
°
Processes
1/0 bound : more time on 110 , less on CPU
°
Context : represented in PCB
•
More time spent on context
switching ,
more time wasted ;
context
switching time is an overhead ; complex OS and PCB
means
longer context switch
OPERATIONS ON PROCESSES
°
creation
-
create
process windows
:
,
for KC ) : linux
°
termination
creation
°
PID : identifier
resource
sharing
•
children share
parents 4 all
-
subset of
I
children share parent 's
no
sharing
°
execution
-
simultaneous
-
sequential
TREE OF PROCESSES IN LINUX
NO
interrupt
daemon :
↳ cannot be
controlled by
terminal
Bourne -
Again
shell
+
login shell
( bash
,
zsh etc)
daemon
od
bash zsh
forKC) : Process creation
°
for KC ) system call : creates new
process
6 variations
←
°
exec C) system call used after forKC) to replace
'
:
process memory
with new
space program
termination
resources deallocated by OS
task no
longer required
-
parent is
terminating (exiting)
-
terminate
-
c-
linux : include memory
wait ( & status)
pid location
-
<
syst wait - h> s
did status)
Zombie : no parent waiting (
parent sleeping; not
get
•
orphan :
executing)
int main() {
int pid;
pid = fork();
if (pid < 0) {
/* without wait L)
1. Too many processes in memory
2. Max children processes
*/
printf("Forking error\n");
exit(1);
}
else if (pid == 0) {
/* Child process */
For more -
man fork
printf("Child process\n");
} man wait
else {
/*
Wait for child process to finish executing
NULL - irrespective of status of child process
*/
wait(NULL);
/* Parent process - ID of child process */
printf("Parent process\n");
}
return 0;
}
exec commands
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
int pid;
pid = fork();
Terminal
if (pid < 0) {
/*
1. Too many processes in memory
2. Max children processes
*/
printf("Forking error\n");
exit(1);
}
else if (pid == 0) {
/* Child process */
printf("Child process\n");
execl("/bin/ls", "ls", NULL);
2
}
after
anything
else { is not run
/*
Wait for child process to finish executing
NULL - irrespective of status of child process
*/
wait(NULL);
/* Parent process - ID of child process */
printf("Parent process\n");
}
return 0;
}
Arguments
yargumfontsommand
execl("/bin/ls", "ls", "-l", NULL);
CPU SCHEDULING
free ,
Single core system only one
process at time Once CPU is
•
: a .
next
process
CPU utilisation
Multiprogramming maximise and minimise
idling
•
:
Several in at
processes memory once
•
•
When one
process is
waiting ,
OS takes CPU away from it and
assigns new
process r
yo
Multi core
process of keeping CPU
busy extended to all
°
-
: cores
CPU Scheduler
•
Short term
-
scheduler
Queue unordered
queue tree
°
: FIFO , linked list
, ,
°
records : PCB
Preemptive and Non -
Preemptive scheduling
•
when a
process
1 .
switches from running to
waiting -
1/0 , event
2. switches from
running to
ready -
interrupt
3 switches from
.
waiting to
ready
4. terminates
wait state
completion with CPU
,
switching to
others :
preemptive process asked to release CPU
involuntarily
° -
} rcaoncedition
-
Preemptive used
scheduling by most oses
•
scheduler
context
switching
-
jumping to restart
-
scheduling criteria
.
CPU Utilisation :
-40.1 .
to -90.1 . (Max)
wait t
d CPU
•
Turnaround time : time taken to execute particular process burst
(min) -
performance metric
1 .
First come , First serve CFCFS)
-
executed in order of arrival
effect : shorter
Jonny
tasks after long
tasks
for of P . -24
waiting
°
time P, -
-
O t -
a
-
for Pa 24 of 13=27
waiting time
-
-
,
t -
for of
waiting time 13=27 t a 13=30
-
turnaround time 27
average
. -
-
.
if arrival order Pz ,
Ps ,
P
,
P, 6
°
tw =
, Pz -
- O
,
Pz =3
,
average tw =3
tea 17=30 , Pa =3 Pg 6
average tea 13
=
-
°
-
, ,
Shortest Job First CSJF)
2
.
Scheduling
with shorter CPU burst time executed first
process
°
optimal minimum
average waiting time
• -
knowing the
length of next
process difficulty
e -
°
Gantt chart for SJF
of Next
Predicting length CPU Burst
T T
predicted Ed El
Q: calculate with T, 10 and
exponential averaging
=
,
2=0.5 the
with
algorithm is SJF
previous runs as 8,7 , 4,16
Possible order : 4, 7 ,
8
,
16
Tnt ; L tht Ll d)
-
Tn
72=0.5×4 t 0.5×10 =
7
Try =
0.5×7+0.5×7 =
7
T, = 10
Ti 7
Tz 7
-
-
74--7.5
PREDICTION
EFFECT of L
o
L = O :
Tnt , =
In
previous round does not effect
•
2=1 :
Tnt , =
tn
CPU burst
only previous counts
Q:
(i )
P, Pz Pz
O 8 12 13
(Ii) Ps Pz P,
O 1 5 13
3
3 .
Shortest Remaining Time First CSRTF) scheduling
°
°
arrival time taken into account ( current time -
arrival)
if has
preempt currently executing process new
process
•
wait
9 7 7
time 0 3 2
15 9
2 5
°
Gantt chart
c- preempted
turnaround time =
exit time -
arrival time
non
preemptive
-
SJF is
priority scheduling algorithm where
priority is
°
•
Problem = starvation (never executed if
priority very low)
Q: arrival) Find
Non -
avg wait
time .
K Ps P, Pz Py
O 1 6 16 18 19
5
Q: Preemptive
Arrival time
:
4
5
P, R P, Ps R Ps R,
.
O 2 3 7 12 16 18 19
average =
( 16 -
O -
lo) -113-2
-
1) + ( 18-4 2) 1- ( 19
- -
5- 1) +
(12-7-5)
wait time
5=3,1--6.2
Q:
20 2
Pz
30 6
Pz
P, Pz Pz
O 10 30 60
i .
O context switches
O:
wait time
13 -
O -
9=4
5 -
I -
4=0
22-2-9=11
Po P, Po Pu
O 1 5 13 22
time 5
is
average wait =
=
5 . Round Robin
•
each
process gets a small unit of CPU time ( time
quantum
)
q usually 10 looms
-
if there and
are
processes in
ready queue
the the time
•
n
time
quantum is q , then
each
process gets yn of the CPU
q should
be
°
overhead switches)
small high (too context
→
too
many
-
Q: 4
q
-
Gantt chart
O: if
q
-
- 2 for prev question
P, Pz B P , 13/4 P, P, P, P, P, P, P, P, P, P,
shorter
q ,
more context switches
( burst)
(
Turnaround Time and Time Quantum
burst
←
time
%
%
"
il
%
%
↳ FIFO
Windows
Linux use RR
scheduling
°
Multilevel
6 .
scheduling
e
ready queue → 2
separate partitions
foreground (interactive)
-
( batch)
background
-
process permanently in a
given queue
°
each
scheduling algorithm
queue
•
:
foreground RR :
background FCFS :
-
in background
run run in
foreground
no . of queues
each
queue 's scheduling algorithm
-
a
process
-
service
•
three queues -
example
-
do : RR -
quantum 8ms
-
O, : RR -
quantum 16 MS
Oz : FCFS
Scheduling
°
- new
job enters Go ,
served FCFS
-
if not completed ,
moved to Qi
-
Q, served FCFS
-
Az is FCFS
MULTIPLE PROCESSOR SCHEDULING
processor own
:
ready queue
•
Modern oses : Windows Linux MacOS support SMP
, ,
threads
private
ready
queue
•
each
processor
: own cache ; buffer
-
buffer of cache
populated with process data
core 1
}
core
cache
- populated
cache with P ,
]
^
flushed n
data
PI data in migrated
buffer
I
Processor
affinity has affinity for processor which it is
•
:
process on
currently running
soft affinity OS
keeps same core (tries not
-
process on
:
to
migrate) but not
guaranteed
hard affinity allows
process to
migrate between
processors
-
-
Linux : soft affinity
sched set affinity C) system call
supports hard affinity
-
-
-
ACCESS to MEMORY
•
Main
memory architecture can affect processor affinity
/
on
chip
memory
and
Scheduling memory placement algorithms work
together
°
LOAD BALANCING
•
SMP tasks ( each CPU own task)
Push load
migration periodic task checks on each CPU and pushes
•
:
Multiple cores on
single chip
Faster, less
power
°
threads
Multiple hardware
idling CPU
•
,
request memory for data another thread
Memory stall takes time ;
°
:
,
c
compute cycle m
memory cycle
thread
> c M C M C M C M
]
time
thread .
J c M C M C M C
thread o
, c M C M C M C
]
time
Chip Multithreading
CMT each
assigned
-
core
-
multiple threads
Intel :
hyperthreading
°
°
Quad -
core system with 2 threads
to the OS
per core :
logically 8 cores
( ID
cat /proc/cpuinfo | more page
O c- logical cores
O ← cores
Multithreading
n
. .
coarse
grained
thread executed on processor until long latency event such
•
-
as
memory stall
of
cost
switching is
high
°
-
state is saved
2 . Fine
grained
-
cost lower
finer level of
granularity
.
Multithreaded multicore Processor
°
two levels of scheduling
physical core
Real-Time CPU
scheduling
embedded real time CPUs
systems
°
-
D soft Real-Time
systems
as to when task is scheduled
no
guarantee
-
2) Hard Real -
Time systems
must be serviced deadline
by
°
of
preemption process
-
Kemal mode
running in
low
-
release by priority
process of resources needed
by high priority
scheduling
ALGORITHMS
1 .
Priority -
based
Scheduling
preemptive
.
.
soft real -
time , not hard
°
CPU required at constant
intervals
t: time
processing
o
d :
deadline
p :
period
O Et E d Ep
•
rate of periodic task -
-
YP
Monotonic
2 . Rate
scheduling
of period
inverse
priority
°
:
CPU utilisation =
ti 50
Pa 100
p,
-
-
-
-
Pi t = 20 ta
-
-
35
,
(
case 1 : P2 priority higher than P1
priority should be
based on period)
Pa P, P, needs to
o
35 55
complete before 50
misses deadline
Case 2 : Pl
priority higher than P2 missed deadlines
R , Pz
←
P, Pz P, Pz n
P,
O 20 50 70 85 / 100 120
idles
PI misses deadline
misses deadline
←
Pa P,
priority order
also
°
35 60
wrong
•
worst case utilisation of CPU for N
processes = NC 24N
-
I )
3 .
Earliest Deadline First LEDF)
Scheduling
priorities assigned dynamically according to deadlines
°
deadline
.
earlier the
, higher the
priority
.
soft real -
time
O: consider processes with p,
= 50
,
ti -
- 25 ,
pz
-
- so
,
ta -
- 35
4 .
Proportional share
scheduling
°
T shares allocated all
among processes
each
app NIT of time CN shares)
•
processor
:
eg
:
A → 50
not more
B → 15 85 shares
than 15 more
c → 20 can be allocated
POSIX
5 .
Real-Time
scheduling
°
POSIX 1b . standard
API
provides functions for threads in real time
managing
° -
Scheduling classes
•
for equal
time
slicing priority
-
similar to
2 SCHED RR : FIFO but time
slicing occurs
-
.
-
) →
teal time priority O
priority scheduling
OT
f v
priority twitching
-
check slides
-
see : red black
-
trees
Windows machine
-
check slides
inter process communication
-
processes :
independent or
cooperating
.
"
do not affect t
each other affect each
other
cooperating processes
°
information sharing
-
modularity dependency
-
: cores
,
-
convenience
•
communication models
✓ shared
segment
(buffer)
Producer -
consumer Model
.
Producer can keep producing data and writing into
buffer
°
no
practical limit on buffer
2 . Bounded buffer
°
Producer waits when buffer full
•
consumer waits when buffer empty
implemented as circular
array
#define BUFFER_SIZE 10
typedef struct {
...
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
0 I 2 3 4 5 6 7 8 9
printout empty : in -
- out
O l 2 3 4 5 6 7 8 9
Producer
item next_produced;
while (true) {
/* produce an item in next_produced */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
consumer
item next_consumed;
while (true) {
while (in == out); /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
/* consume the item in next_consumed */
}
fhaled MEMORY
>
fastest form of IPC
ceg client q )
.
semaphores : shared
memory access
message passing
send ( receive (
IPC message) message)
•
:
,
°
if P g Q wish to communicate, they must
via
2.
exchange messages send I receive
direct / indirect
logical link :
synclasync automatic explicit
°
, ,
buffering
Defect COMMUNICATION
receive co ,
message)
usually bidirectional
unique ID
Indirect COMMUNICATION
I
•
if share mailbox
only processes a
they communicate
•
,
can
connect several
process
•
link : Uni or bidirectional
create new
port / mailbox
•
°
issues : P, sends to shared mailbox with Rz
, Rz ; who
gets message?
Blocking Ee Non -
Blocking
Blocking
Synchronous
°
Non
blocking
-
asynchronous
•
message
Buffering
attached to for
queues of messages link ;
temporary queue
•
messages
system with
message
no
buffering
queues :
.
y
l .
zero
capacity :
queue; sender waits for receiver; rendezvous
no
full automatic
buffering
3 unbounded infinite sender waits
.
capacity :
length ; never
Pipes
°
half -
child
p ,
no
relationship
ordinary (unnamed) and named
pipes pipes
-
Ordinary Pipes
O -
stain
fd[ D O ) fdco] I -
Std out
↳ write I 2- stderr
read
half (unidirectional)
•
-
duplex
for two
.
way , two
pipes
-
Linux Windows :
:
pipe anonymous pipes
°
Named Pipes
bidirectional no
parent-child relationship
°
,
-
several processes same
pipe
way
-
°
FIFO : once retrieved
,
data removed
°
UNIX :
read C ) write C) , close c)
mkfifoc) ,open C) ,
-
byte oriented
-
half -
duplex
-
same machine
°
Windows
-
Create Named Pipe ,
connect Named Pipe c) ,
Read Fila) ,
write Filet ), Disconnect Named Pipe l )
-
full duplex
-
same or different machine
byte or
message oriented
-
← read
end
O
T
write [ pipe pipeline
-
end
operator
Search for Pattern
for:L
'
.
I
pipe
fifo file
of
% ↳
normal
pipe
manual entry L2)
system call
-
manual 4) command
entry
-
pipe -
c
Ubuntu
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main() {
int fd[2]; MacOS
char buf[5];
pipe(fd);
write(fd[1], "hello", 5);
read(fd[0], buf, 5);
write(1, buf, 5);
printf("\n");
return 0;
}
One way communication
-
#include <stdio.h>
#include <unistd.h> output
#include <stdlib.h>
int main() {
int fd[2];
char buf[12];
int pid;
pipe(fd);
pid = fork();
if (pid < 0) {
printf("error\n");
exit(1);
Two communication
}
way
-
if (pid < 0) {
printf("error\n");
exit(1);
}
else if (pid == 0) {
close(fd[0]);
write(fd[1], "I am child\n", 12);
read(fd1[0], buf1, 7);
write(1, buf1, 7);
}
else {
close(fd[1]);
read(fd[0], buf, 12);
write(fd1[1], "parent\n", 7);
write(1, buf, 12);
}
return 0;
}