SlideShare a Scribd company logo
Inter Process
Communication
Mrs. Sowmya Jyothi, Faculty, Mangalore
References:
The Design of the UNIX Operating System
by Maurice J. Bach
• Inter Process Communication is a
mechanism whereby one process
communicates with another process.
• Communication means exchange of
data.
• The directions can be unidirectional,
bidirectional or multidirectional.
Inter Process Communication
Process Tracing:-
The unix system provides a primitive form of interprocess
communication for tracing processes, useful for debugging.
A debugger process takes as an input a process to be traced
and controls its execution with the PTRACE SYSTEM
CALL, setting and clearing break points, and reading and
writing data in its virtual address space.
Process tracing thus consists of synchronization of the
debugger process and the traced process and controlling
the execution of the traced process.
The ptrace() system call provides tracing and debugging
facilities.
The debugger takes as an input a child process,
which involves the ptrace system call and as a
result, the kernel sets a trace bit in the child
process table entry. The child now execs the
program being traced.
The trace bit is set in its process table entry, the
child awakens the parent from its sleep in the wait
system call, enters a special trace state similar to
the sleep state and does a context switch.
When the traced process awakens the debugger,
the debugger returns from wait, reads user input
commands, and converts them to a series of ptrace
calls to control the child(traced) process.
The syntax of the ptrace system call is
ptrace(cmd, pid, addr, data)
where cmd specifies various commands such as
reading data, writing data, resuming execution
and so on,
pid is the process ID of the traced process,
 addr is the Virtual address to be read or written
in the child process,
and data is an integer value to be written.
Unix Versions
System V IPC:-
The Unix system IPC package consists of 3
mechanisms.
1. Messages allow processes to send formatted
data streams to arbitrary processes.
2. Shared memory allow processes to share parts
of their virtual address space
3. Semaphores allow processes to synchronize
execution.
Common properties shared by the mechanisms are:
1. Each mechanism contains a table whose entries
describe all instances of the mechanism.
2. Each entry contains a numeric key.
3. Each mechanism contains a “get” system call to create a
new entry or to retrieve an existing one and parameters
to the calls include a key and flags..
4. For each IPC mechanism, the kernel uses the
following formula to find the index into the table of
data structures from the descriptor:
Index=descriptormodulo(number of entries in the
table).
5. Each IPC entry has a permissions structure that
includes the User ID and group ID of the process that
created the entry, a user and group ID set by the
“control” system call and a set of read-write-execute
permissions for user, group, and others similar to the
file permission modes.
6. Each entry contains other status information such as
the process ID of the last process to update the entry
(send a message, receive a message, attach shared
memory and so on) and the time of last access or
update.
7. Each mechanism contains a “control” system call to
query status of an entry, to set status information, or
to remove the entry from the system.
MESSAGES
There are four system calls for messages:
msgget returns (and possibly creates) a message
descriptor.
msgctl has options to set and return parameters
associated with a message descriptor and an
option to remove descriptors.
msgsnd sends a message.
msgrcv receives a message.
1. Message Passing
IPC facility provides two operations for fixed or
variable sized message:
◦send(message)
◦receive(message)
If processes P and Q wish to communicate, they
need to:
◦establish a communication link
◦exchange messages via send and receive
View of communication link:
◦physical (hardware bus, network links, shared
memory, etc.)
◦logical (syntax and semantics, abstractions)
14
A MESSAGE QUEUE is a queue onto which messages
can be placed.
A MESSAGE is composed of a message type (which is a
number), and message data.
A message queue can be either PRIVATE, OR PUBLIC.
If it IS PRIVATE, it can be accessed only by its creating
process or child processes of that creator.
If it's PUBLIC, it can be accessed by any process that
knows the queue's key.
Several processes may write messages onto a
message queue, or read messages from the queue.
Messages may be read by type, and thus not have to
be read in a FIFO order as is the case with pipes.
MESSAGES:-
There are 4 system calls for messages.
1. msgget- In order to use a message queue, it has to be
created first. In order to create a new message queue, or
access an existing queue, the msgget() system call is used.
Returns a message descriptor that designates a message
queue for use in other system calls.
Syntax: msgqid=msgget(key, flag)
Where msgqid is the descriptor returned by the call.
The Kernel stores messages on a linked list (queue) per
descriptor and it uses msgqid as an index into an array
of message queue headers.
The queue structure contains the following fields, in
addition to the common fields:
1. Pointers to the first and last messages on a linked
list.
2. The number of messages and total number of data
bytes on the linked list.
3. The maximum number of bytes of data that can be
on the linked list.
4. The process IDs of the last processes to send and
receive messages.
5. Time stamps of the last msgsnd, msgrcv,
and msgctl operations.
2. A process uses the msgsnd system call to
send a message.
msgsnd(msgqid, msg, count, flag);
1. Where msgqid is the descriptor of a message
queue typically returned by a msgget call,
2. Msg is a pointer to a structure consisting of a
user-chosen integer type and a character
array,
3. Count gives the size of the data array
4. Flag specifies the action the kernel should
take if it runs out of internal buffer space.
flags specifying how to send the message.
3. Reading A Message From The Queue -msgrcv()
count = msgrcv(id, msg, maxcount, type, flag)
1. Where id- is the message descriptor
2. Msg-is the address of a user structure to contain
the received message
3. Maxcount-is the size of the data array in msg,
4. Type-specifies the message type the user wants to
read
5. Flag-specifies what the kernel should do if
messages are on the queue.
6. The return value count, is the number of bytes
returned to the user.
4. A PROCESS can query the status of a message
descriptor, set its status and remove a message
descriptor with the msgctl system call.
The syntax of the call is msgctl(id, cmd, mstatbuf)
Where id-message descriptor
cmd specifies the type of command
mstatbuf is the address of a user data structure that
will contain control parameters or the result of query.
2. Shared Memory
1. Allows two or more processes to share
some memory segments
2. With some control over read/write
permissions
2. Shared Memory:-
Processes can communicate directly with each other by
sharing parts of their virtual address space and then reading
and writing data stored in the shared memory.
Sharing the part of virtual memory and reading to and
writing from it, is another way for the processes to
communicate. The system calls are:
1. shmget creates a new region of shared memory or returns
an existing one.
2. shmat logically attaches a region to the virtual address
space of a process.
3. shmdt logically detaches a region.
4. shmctl manipulates the parameters associated with the
region.
1. The shmget system call creates a new region of shared
memory or returns an existing one.
Syntax: shmid=shmget(key, size, flag)
key: Identical to msgget
size: Size of the memory segment if a creating a new
segment, can use 0 if getting an existing segment. Is the
number of bytes in the region.
flags: Identical to msgget.
Just like msgget, shmget could:
1. Create a new memory segment.
2. Return the queue ID of an existing segment.
3. Signal an error.
2. A process attaches a shared memory region to its virtual
address space with the shmat system call.
Syntax: virtaddr = shmat(id, addr, flags)
Before the memory can be used, it must be attached by the
process and assigned a memory address.
1. shmid: id of shared memory segment as returned by
shmget.
2. addr: If 0, address is selected by kernel (recommended).
Otherwise, segment is attached at supplied address.
3. flags: Control behavior of attachment. SHM_RDONLY makes
the segment read-only.
4. Returns a pointer to the shared memory segment.
3. Detaching Shared Memory Segments: Detaches
the shared memory segment located at the
address indicated by shmaddr.
The Syntax for shmdt: shmdt(addr);
where addr is the virtual address returned by a
prior shmat call.
4. shmctl manipulates the parameters associated
with the region.
Syntax of shmctl
shmctl(id, cmd, shmstatbuf);
which is similar to msgctl
3. Semaphores:-
A semaphore is a resource that contains an integer value,
and allows processes to synchronize by testing and setting
this value in a single atomic operation.
A SEMAPHORE is UNIX System V consists of the following
elements:
1. The value of the semaphore.
2. The process ID of the last process to manipulate the
semaphore.
3. The number of processes waiting for semaphore value
to increase.
4. The number of processes waiting for the semaphore
value to equal 0.
The system calls are:
1. semget to create and gain access to a set of
semaphores.
2. semctl to do various control operations on the set.
3. semop to manipulate the values of semaphores.
1. Creation of a semaphore set - semget creates an array
of semaphores:
id = semget(key, count, flag);
Flag- used to define access permission mode and a few options
The kernel allocates an entry that points to an array of
semaphore structure with count elements
2. Processes manipulate semaphores with
the semop system call:
oldval = semop(id, oplist, count);
where oplist is a pointer to an array of semaphore
operations, and
count is the size of the array.
The return value, oldval, is the value of the last
semaphore operated on in the set before the
operation was done.
The format of each element of oplist is,
•The semaphore number identifying the semaphore
array entry being operated on
•The operation
•Flags
Sockets
To provide common methods for interprocess
communication and to allow use of sophisticated
network protocols, the BSD system provides a
mechanism known as sockets.
A socket is an IPC channel with generated
endpoints.
Intended as building block for communication
Endpoints established by the source and
destination processes
The kernel structure consists of three parts:
the socket layer, the protocol layer, and the
device layer, as shown in the figure:
1. The Socket layer provides the interface
between the system calls and the lower layers.
2. The Protocol layer contains the protocol
modules used for communication, and
3. The Device layer contains the device drivers
that control the network devices.
Sockets that share common communications
properties, such as naming conventions and
protocol address formats, are grouped
into domains.
1. The socket system call establishes the
end point of a communications link.
sd = socket(format, type, protocol);
where format specifies the
communications domain,
type indicates the type of
communication over the socket,
 and protocol indicates a particular
protocol to control the communication.
2. The close system call - closes sockets.
3. The bind system call associates a name
with the socket descriptor.
Binding prepares a socket for use by a process
bind(sd, address, length);
where address points to a structure that
specifies an identifier specific to the
communications domain and protocol
specified in the socket system call.
length is the length of the address structure.
4. The connect system call requests
that the kernel make a connection to
an existing socket:
connect(sd, address, length);
where address is the address of the
target socket. Both sockets must use
the same communications domain and
protocol.
5. The listen system call specifies the
maximum queue length:
listen(sd, qlength);
6. The accept call receives incoming requests
for a connection to a server process:
nsd = accept(sd, address, addrlen);
where address points to a user data array that
the kernel fills with the return address of the
connecting client, and
addrlen indicates the size of the user array.
7. The send and recv system calls transmit data over
a connected socket:
count = send(sd, msg, length, flags);
count = recv(sd, buf, length, flags);
The datagram versions of these system
calls, sendto and recvfrom have additional parameters
for addresses.
Processes can also use read and write system calls on
stream (virtual circuit) sockets after the connection is
set up.
8. The shutdown system call closes a socket
connection:
shutdown(sd, mode);
where mode indicates whether the sending side, the
receiving side, or both sides no longer allow data
transmission. After this call, the socket descriptors are
still intact.
9. The close system call frees the socket descriptor.
10. The getsocketname system call gets the
name of a socket bound by a
previous bind call:
getsocketname(sd, name, length);
The getsockopt and setsockopt calls retrieve
and set various options associated with the
socket, according to the communications domain
and protocol of the socket.

More Related Content

What's hot

Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
subhsikha
 
Case study windows
Case study windowsCase study windows
Case study windows
Padam Banthia
 
Intro to linux systems administration
Intro to linux systems administrationIntro to linux systems administration
Intro to linux systems administration
Padam Banthia
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
Saadi Rahman
 
Unix kernal
Unix kernalUnix kernal
Architecture of operating system
Architecture of operating systemArchitecture of operating system
Architecture of operating system
Supriya Kumari
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
Goutam Sahoo
 
Kernal
KernalKernal
Kernal
Ramasubbu .P
 
OS - Ch2
OS - Ch2OS - Ch2
OS - Ch2
sphs
 
Introduction to System Calls
Introduction to System CallsIntroduction to System Calls
Introduction to System Calls
Vandana Salve
 
unix training | unix training videos | unix course unix online training
unix training |  unix training videos |  unix course  unix online training unix training |  unix training videos |  unix course  unix online training
unix training | unix training videos | unix course unix online training
Nancy Thomas
 
OSCh21
OSCh21OSCh21
Case study
Case studyCase study
Case study
Usha Ravichandran
 
UNIX Operating System ppt
UNIX Operating System pptUNIX Operating System ppt
Linux kernel architecture
Linux kernel architectureLinux kernel architecture
Linux kernel architecture
Teja Bheemanapally
 
Os concepts
Os conceptsOs concepts
Case study operating systems
Case study operating systemsCase study operating systems
Case study operating systems
Akhil Bevara
 
OSCh20
OSCh20OSCh20

What's hot (18)

Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Case study windows
Case study windowsCase study windows
Case study windows
 
Intro to linux systems administration
Intro to linux systems administrationIntro to linux systems administration
Intro to linux systems administration
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
 
Unix kernal
Unix kernalUnix kernal
Unix kernal
 
Architecture of operating system
Architecture of operating systemArchitecture of operating system
Architecture of operating system
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Kernal
KernalKernal
Kernal
 
OS - Ch2
OS - Ch2OS - Ch2
OS - Ch2
 
Introduction to System Calls
Introduction to System CallsIntroduction to System Calls
Introduction to System Calls
 
unix training | unix training videos | unix course unix online training
unix training |  unix training videos |  unix course  unix online training unix training |  unix training videos |  unix course  unix online training
unix training | unix training videos | unix course unix online training
 
OSCh21
OSCh21OSCh21
OSCh21
 
Case study
Case studyCase study
Case study
 
UNIX Operating System ppt
UNIX Operating System pptUNIX Operating System ppt
UNIX Operating System ppt
 
Linux kernel architecture
Linux kernel architectureLinux kernel architecture
Linux kernel architecture
 
Os concepts
Os conceptsOs concepts
Os concepts
 
Case study operating systems
Case study operating systemsCase study operating systems
Case study operating systems
 
OSCh20
OSCh20OSCh20
OSCh20
 

Similar to Inter Process Communication PPT

Unit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdfUnit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdf
AnilkumarBrahmane2
 
Os notes
Os notesOs notes
Os notes
LakshmiSarvani6
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
Mohd Tousif
 
Operating system
Operating systemOperating system
Operating system
Kinza Razzaq
 
ipc.pptx
ipc.pptxipc.pptx
ipc.pptx
SuhanB
 
Distributed system lectures
Distributed system lecturesDistributed system lectures
Distributed system lectures
marwaeng
 
project_531
project_531project_531
project_531
Srivats Bharadwaj
 
LINUX Device Drivers
LINUX Device DriversLINUX Device Drivers
LINUX Device Drivers
Partha Bhattacharya
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
RJ Mehul Gadhiya
 
Provably Secure Authenticated Key Management Protocol Against De-Synchronizat...
Provably Secure Authenticated Key Management Protocol Against De-Synchronizat...Provably Secure Authenticated Key Management Protocol Against De-Synchronizat...
Provably Secure Authenticated Key Management Protocol Against De-Synchronizat...
IJRESJOURNAL
 
Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...
Damir Delija
 
Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...
Damir Delija
 
Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...
Damir Delija
 
Chapter 4 communication2
Chapter 4 communication2Chapter 4 communication2
Chapter 4 communication2
DBU
 
A FPGA-Based Deep Packet Inspection Engine for Network Intrusion Detection Sy...
A FPGA-Based Deep Packet Inspection Engine for Network Intrusion Detection Sy...A FPGA-Based Deep Packet Inspection Engine for Network Intrusion Detection Sy...
A FPGA-Based Deep Packet Inspection Engine for Network Intrusion Detection Sy...
Muhammad Nasiri
 
IPC in Microkernel Systems, Capabilities
IPC in Microkernel Systems, CapabilitiesIPC in Microkernel Systems, Capabilities
IPC in Microkernel Systems, Capabilities
Martin Děcký
 
DS-Chapter DDEFR2-Communication_105220.ppt
DS-Chapter DDEFR2-Communication_105220.pptDS-Chapter DDEFR2-Communication_105220.ppt
DS-Chapter DDEFR2-Communication_105220.ppt
menoralemu03
 
unit_1.pdf
unit_1.pdfunit_1.pdf
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
RashidFaridChishti
 
Chapter 2B-Communication.ppt
Chapter 2B-Communication.pptChapter 2B-Communication.ppt
Chapter 2B-Communication.ppt
sirajmohammed35
 

Similar to Inter Process Communication PPT (20)

Unit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdfUnit_ 5.3 Interprocess communication.pdf
Unit_ 5.3 Interprocess communication.pdf
 
Os notes
Os notesOs notes
Os notes
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Operating system
Operating systemOperating system
Operating system
 
ipc.pptx
ipc.pptxipc.pptx
ipc.pptx
 
Distributed system lectures
Distributed system lecturesDistributed system lectures
Distributed system lectures
 
project_531
project_531project_531
project_531
 
LINUX Device Drivers
LINUX Device DriversLINUX Device Drivers
LINUX Device Drivers
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Provably Secure Authenticated Key Management Protocol Against De-Synchronizat...
Provably Secure Authenticated Key Management Protocol Against De-Synchronizat...Provably Secure Authenticated Key Management Protocol Against De-Synchronizat...
Provably Secure Authenticated Key Management Protocol Against De-Synchronizat...
 
Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...
 
Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...
 
Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...Communication network simulation on the unix system trough use of the remote ...
Communication network simulation on the unix system trough use of the remote ...
 
Chapter 4 communication2
Chapter 4 communication2Chapter 4 communication2
Chapter 4 communication2
 
A FPGA-Based Deep Packet Inspection Engine for Network Intrusion Detection Sy...
A FPGA-Based Deep Packet Inspection Engine for Network Intrusion Detection Sy...A FPGA-Based Deep Packet Inspection Engine for Network Intrusion Detection Sy...
A FPGA-Based Deep Packet Inspection Engine for Network Intrusion Detection Sy...
 
IPC in Microkernel Systems, Capabilities
IPC in Microkernel Systems, CapabilitiesIPC in Microkernel Systems, Capabilities
IPC in Microkernel Systems, Capabilities
 
DS-Chapter DDEFR2-Communication_105220.ppt
DS-Chapter DDEFR2-Communication_105220.pptDS-Chapter DDEFR2-Communication_105220.ppt
DS-Chapter DDEFR2-Communication_105220.ppt
 
unit_1.pdf
unit_1.pdfunit_1.pdf
unit_1.pdf
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
 
Chapter 2B-Communication.ppt
Chapter 2B-Communication.pptChapter 2B-Communication.ppt
Chapter 2B-Communication.ppt
 

More from Sowmya Jyothi

Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
Sowmya Jyothi
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Sowmya Jyothi
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Sowmya Jyothi
 
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
Sowmya Jyothi
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
Sowmya Jyothi
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
Sowmya Jyothi
 
Introduction to graphics
Introduction to graphicsIntroduction to graphics
Introduction to graphics
Sowmya Jyothi
 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
Sowmya Jyothi
 

More from Sowmya Jyothi (17)

Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
 
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
 
Introduction to graphics
Introduction to graphicsIntroduction to graphics
Introduction to graphics
 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
 

Recently uploaded

Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 

Inter Process Communication PPT

  • 1. Inter Process Communication Mrs. Sowmya Jyothi, Faculty, Mangalore References: The Design of the UNIX Operating System by Maurice J. Bach
  • 2. • Inter Process Communication is a mechanism whereby one process communicates with another process. • Communication means exchange of data. • The directions can be unidirectional, bidirectional or multidirectional. Inter Process Communication
  • 3.
  • 4. Process Tracing:- The unix system provides a primitive form of interprocess communication for tracing processes, useful for debugging. A debugger process takes as an input a process to be traced and controls its execution with the PTRACE SYSTEM CALL, setting and clearing break points, and reading and writing data in its virtual address space. Process tracing thus consists of synchronization of the debugger process and the traced process and controlling the execution of the traced process. The ptrace() system call provides tracing and debugging facilities.
  • 5. The debugger takes as an input a child process, which involves the ptrace system call and as a result, the kernel sets a trace bit in the child process table entry. The child now execs the program being traced. The trace bit is set in its process table entry, the child awakens the parent from its sleep in the wait system call, enters a special trace state similar to the sleep state and does a context switch. When the traced process awakens the debugger, the debugger returns from wait, reads user input commands, and converts them to a series of ptrace calls to control the child(traced) process.
  • 6. The syntax of the ptrace system call is ptrace(cmd, pid, addr, data) where cmd specifies various commands such as reading data, writing data, resuming execution and so on, pid is the process ID of the traced process,  addr is the Virtual address to be read or written in the child process, and data is an integer value to be written.
  • 8. System V IPC:- The Unix system IPC package consists of 3 mechanisms. 1. Messages allow processes to send formatted data streams to arbitrary processes. 2. Shared memory allow processes to share parts of their virtual address space 3. Semaphores allow processes to synchronize execution.
  • 9. Common properties shared by the mechanisms are: 1. Each mechanism contains a table whose entries describe all instances of the mechanism. 2. Each entry contains a numeric key. 3. Each mechanism contains a “get” system call to create a new entry or to retrieve an existing one and parameters to the calls include a key and flags.. 4. For each IPC mechanism, the kernel uses the following formula to find the index into the table of data structures from the descriptor: Index=descriptormodulo(number of entries in the table).
  • 10. 5. Each IPC entry has a permissions structure that includes the User ID and group ID of the process that created the entry, a user and group ID set by the “control” system call and a set of read-write-execute permissions for user, group, and others similar to the file permission modes. 6. Each entry contains other status information such as the process ID of the last process to update the entry (send a message, receive a message, attach shared memory and so on) and the time of last access or update. 7. Each mechanism contains a “control” system call to query status of an entry, to set status information, or to remove the entry from the system.
  • 11.
  • 12.
  • 13. MESSAGES There are four system calls for messages: msgget returns (and possibly creates) a message descriptor. msgctl has options to set and return parameters associated with a message descriptor and an option to remove descriptors. msgsnd sends a message. msgrcv receives a message.
  • 14. 1. Message Passing IPC facility provides two operations for fixed or variable sized message: ◦send(message) ◦receive(message) If processes P and Q wish to communicate, they need to: ◦establish a communication link ◦exchange messages via send and receive View of communication link: ◦physical (hardware bus, network links, shared memory, etc.) ◦logical (syntax and semantics, abstractions) 14
  • 15. A MESSAGE QUEUE is a queue onto which messages can be placed. A MESSAGE is composed of a message type (which is a number), and message data. A message queue can be either PRIVATE, OR PUBLIC. If it IS PRIVATE, it can be accessed only by its creating process or child processes of that creator. If it's PUBLIC, it can be accessed by any process that knows the queue's key. Several processes may write messages onto a message queue, or read messages from the queue. Messages may be read by type, and thus not have to be read in a FIFO order as is the case with pipes.
  • 16. MESSAGES:- There are 4 system calls for messages. 1. msgget- In order to use a message queue, it has to be created first. In order to create a new message queue, or access an existing queue, the msgget() system call is used. Returns a message descriptor that designates a message queue for use in other system calls. Syntax: msgqid=msgget(key, flag) Where msgqid is the descriptor returned by the call. The Kernel stores messages on a linked list (queue) per descriptor and it uses msgqid as an index into an array of message queue headers.
  • 17. The queue structure contains the following fields, in addition to the common fields: 1. Pointers to the first and last messages on a linked list. 2. The number of messages and total number of data bytes on the linked list. 3. The maximum number of bytes of data that can be on the linked list. 4. The process IDs of the last processes to send and receive messages. 5. Time stamps of the last msgsnd, msgrcv, and msgctl operations.
  • 18. 2. A process uses the msgsnd system call to send a message. msgsnd(msgqid, msg, count, flag); 1. Where msgqid is the descriptor of a message queue typically returned by a msgget call, 2. Msg is a pointer to a structure consisting of a user-chosen integer type and a character array, 3. Count gives the size of the data array 4. Flag specifies the action the kernel should take if it runs out of internal buffer space. flags specifying how to send the message.
  • 19. 3. Reading A Message From The Queue -msgrcv() count = msgrcv(id, msg, maxcount, type, flag) 1. Where id- is the message descriptor 2. Msg-is the address of a user structure to contain the received message 3. Maxcount-is the size of the data array in msg, 4. Type-specifies the message type the user wants to read 5. Flag-specifies what the kernel should do if messages are on the queue. 6. The return value count, is the number of bytes returned to the user.
  • 20. 4. A PROCESS can query the status of a message descriptor, set its status and remove a message descriptor with the msgctl system call. The syntax of the call is msgctl(id, cmd, mstatbuf) Where id-message descriptor cmd specifies the type of command mstatbuf is the address of a user data structure that will contain control parameters or the result of query.
  • 21. 2. Shared Memory 1. Allows two or more processes to share some memory segments 2. With some control over read/write permissions
  • 22. 2. Shared Memory:- Processes can communicate directly with each other by sharing parts of their virtual address space and then reading and writing data stored in the shared memory. Sharing the part of virtual memory and reading to and writing from it, is another way for the processes to communicate. The system calls are: 1. shmget creates a new region of shared memory or returns an existing one. 2. shmat logically attaches a region to the virtual address space of a process. 3. shmdt logically detaches a region. 4. shmctl manipulates the parameters associated with the region.
  • 23.
  • 24. 1. The shmget system call creates a new region of shared memory or returns an existing one. Syntax: shmid=shmget(key, size, flag) key: Identical to msgget size: Size of the memory segment if a creating a new segment, can use 0 if getting an existing segment. Is the number of bytes in the region. flags: Identical to msgget. Just like msgget, shmget could: 1. Create a new memory segment. 2. Return the queue ID of an existing segment. 3. Signal an error.
  • 25. 2. A process attaches a shared memory region to its virtual address space with the shmat system call. Syntax: virtaddr = shmat(id, addr, flags) Before the memory can be used, it must be attached by the process and assigned a memory address. 1. shmid: id of shared memory segment as returned by shmget. 2. addr: If 0, address is selected by kernel (recommended). Otherwise, segment is attached at supplied address. 3. flags: Control behavior of attachment. SHM_RDONLY makes the segment read-only. 4. Returns a pointer to the shared memory segment.
  • 26. 3. Detaching Shared Memory Segments: Detaches the shared memory segment located at the address indicated by shmaddr. The Syntax for shmdt: shmdt(addr); where addr is the virtual address returned by a prior shmat call. 4. shmctl manipulates the parameters associated with the region. Syntax of shmctl shmctl(id, cmd, shmstatbuf); which is similar to msgctl
  • 27. 3. Semaphores:- A semaphore is a resource that contains an integer value, and allows processes to synchronize by testing and setting this value in a single atomic operation. A SEMAPHORE is UNIX System V consists of the following elements: 1. The value of the semaphore. 2. The process ID of the last process to manipulate the semaphore. 3. The number of processes waiting for semaphore value to increase. 4. The number of processes waiting for the semaphore value to equal 0.
  • 28. The system calls are: 1. semget to create and gain access to a set of semaphores. 2. semctl to do various control operations on the set. 3. semop to manipulate the values of semaphores. 1. Creation of a semaphore set - semget creates an array of semaphores: id = semget(key, count, flag); Flag- used to define access permission mode and a few options The kernel allocates an entry that points to an array of semaphore structure with count elements
  • 29. 2. Processes manipulate semaphores with the semop system call: oldval = semop(id, oplist, count); where oplist is a pointer to an array of semaphore operations, and count is the size of the array. The return value, oldval, is the value of the last semaphore operated on in the set before the operation was done. The format of each element of oplist is, •The semaphore number identifying the semaphore array entry being operated on •The operation •Flags
  • 30. Sockets To provide common methods for interprocess communication and to allow use of sophisticated network protocols, the BSD system provides a mechanism known as sockets. A socket is an IPC channel with generated endpoints. Intended as building block for communication Endpoints established by the source and destination processes The kernel structure consists of three parts: the socket layer, the protocol layer, and the device layer, as shown in the figure:
  • 31.
  • 32. 1. The Socket layer provides the interface between the system calls and the lower layers. 2. The Protocol layer contains the protocol modules used for communication, and 3. The Device layer contains the device drivers that control the network devices. Sockets that share common communications properties, such as naming conventions and protocol address formats, are grouped into domains.
  • 33. 1. The socket system call establishes the end point of a communications link. sd = socket(format, type, protocol); where format specifies the communications domain, type indicates the type of communication over the socket,  and protocol indicates a particular protocol to control the communication.
  • 34. 2. The close system call - closes sockets. 3. The bind system call associates a name with the socket descriptor. Binding prepares a socket for use by a process bind(sd, address, length); where address points to a structure that specifies an identifier specific to the communications domain and protocol specified in the socket system call. length is the length of the address structure.
  • 35. 4. The connect system call requests that the kernel make a connection to an existing socket: connect(sd, address, length); where address is the address of the target socket. Both sockets must use the same communications domain and protocol.
  • 36. 5. The listen system call specifies the maximum queue length: listen(sd, qlength); 6. The accept call receives incoming requests for a connection to a server process: nsd = accept(sd, address, addrlen); where address points to a user data array that the kernel fills with the return address of the connecting client, and addrlen indicates the size of the user array.
  • 37. 7. The send and recv system calls transmit data over a connected socket: count = send(sd, msg, length, flags); count = recv(sd, buf, length, flags); The datagram versions of these system calls, sendto and recvfrom have additional parameters for addresses. Processes can also use read and write system calls on stream (virtual circuit) sockets after the connection is set up.
  • 38. 8. The shutdown system call closes a socket connection: shutdown(sd, mode); where mode indicates whether the sending side, the receiving side, or both sides no longer allow data transmission. After this call, the socket descriptors are still intact. 9. The close system call frees the socket descriptor.
  • 39. 10. The getsocketname system call gets the name of a socket bound by a previous bind call: getsocketname(sd, name, length); The getsockopt and setsockopt calls retrieve and set various options associated with the socket, according to the communications domain and protocol of the socket.