Inter process communication l.jpg
This presentation is the property of its rightful owner.
Sponsored Links
1 / 29

Inter Process Communication PowerPoint PPT Presentation

  • Uploaded on
  • Presentation posted in: General

Inter Process Communication. Signals. kill -l Processes can choose to ignore most of the signals. except: SIGSTOP , SIGKILL Processes handle signals themselves or allow kernel to handle (do default actions). no inherent relative priorities.

Download Presentation

Inter Process Communication

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Inter process communication l.jpg

Inter Process Communication

Signals l.jpg


kill -l

Processes can choose to ignore most of the signals.


Processes handle signals themselves or allow kernel to

handle (do default actions).

no inherent relative priorities.

no mechanism for handling multiple signals of the same


Slide3 l.jpg

Linux implements signals using information stored in the

task_struct for the process.

the number of supported signals is limited to the word

size of the processor. (32/64 bits)

signal (the currently pending signals)

blocked (a mask of blocked signals)

If a blocked signal is generated, it remains pending until

it is unblocked.

Slide4 l.jpg

Linux holds information about how each process handles

every possible signals:

an array of sigaction pointed at by the task_struct for every


the address of routine / let kernel handle it / ignore

Send signals to other processes:

kernel / superuser

the same uid or euid / in the same process group

// uid and gid

Slide5 l.jpg

Signals are not presented to the process immediately when

they are generated. They must wait until the process is

running again.

A process has specified its own signal handler.

Kernel must call the signal handle routine (the sigaction

holds the address).

The program counter is set to the signal handling routine

and the parameters to the routine are added to the call

frame or registers.

Pipes l.jpg


ls | pr | lpr

Use two file which both point at the same temporary VFS

inode which points at the physical page within memory.

file f_inode f_op

Slide8 l.jpg

synchronize access to the pipe: lock, waiting queue, signals

write to the pipe: uses the standard write library functions

enough room to write and not locked

locks it and copies

not enough room or locked

sleep, the pipe inode’s waiting queue,interruptible

When the data has been written, any waiting reader

sleeping on the waiting queue will be woken up.

Non-blocking read: no data to read or locked

an error will be returned

Named pipes fifo l.jpg

Named Pipes (FIFO)

Not temporary objects

mkfifo <path>

prw-r—r– 0 fifo1

Processes are free to use a FIFO so long as they have

appropriate access right to it.

A FIFO already exists. open / close

Linux must handle readers opening the FIFO to read before

writers opening to write.

Pipe / FIFO: the same data structure and operations

System v ipc mechanism l.jpg

System V IPC Mechanism

message queues, semaphore, share memory

key_t ftok (const char * path, int id) ;


int sys_msgget (key_t key, int msgflg) ;

struct ipc_perm {

key_t key ;

ushort uid, gid, cuid, guid ;

ushort mode ;// access right

ushort seq ;// id

} ;

Message queues l.jpg

Message Queues

One or more processes to write/read

msgque vector

struct msgid_ds {

struct ipc_perm msg_perm ;

struct msg * msg_first, * msg_last ;

time_t msg_stime, msg_rtime, msg_ctime ;// send, receive, change

struct wait_queue * wwait, * rwait ;

ushort msg_cbytes ;

ushort msg_qnum ;

ushort msg_qbytes ;

ushort msg_lspid, msg_lrpid ;// send, receive

} ;

Slide12 l.jpg

struct msg {

struct msg * msg_next ;

long msg_type ;

char * msg_spot ;

time_t msg_stime ;// no use

short msg_ts ;// length

} ;

Slide14 l.jpg

Write to the queue:

euid, egid compare with the mode in the queue’s ipc_perm

tagged with an application specific type

no room, the number / the length

added to the message queue’s write waiting queue

Read from the queue :

check access rights

the first message / select messages with particular types

no messages match, read waiting queue

Semapores l.jpg


A location in memory whose value can be tested and set by more than one process.

Test / set: uninterruptible (used to implement critical regions), the addition of the current value of the semaphore and the set value (positive/negative).

Slide16 l.jpg

Example: read/write a file

initial value: 1

two operations: test and decrease / test and increase

the first process : decrease, succeed, 0

another process: decrease, fail, waiting queue

the first process has finished: increase, wake up the process in the waiting queue

Slide17 l.jpg

semary vector

struct semid_ds {

struct ipe_perm sem_perm ;// access right

time_t sem_otime, sem_ctime ;// the last time of operation, change

struct sem * sem_base ;// array of semaphores

struct sem_queue * sem_pending, ** sem_pending_last ;

struct sem_undo * undo ;

unshort sem_nsems ;// the number of semaphores

} ;

struct sem {

short semval ;

short sempid ;

} ;

Slide18 l.jpg









Slide19 l.jpg

If a process does not require non-blocking, will add a sem_queue to semaphore waiting queue.

remove sem_queue, wake up


process crashed or was killed in a critical region.

struct sem_undo {

struct sem_undo * proc_next ;

struct sem_undo * id_next ;

int semid ;

short * semarj ;

} ;

Slide20 l.jpg

Linux will maintain at most one sem_undo per process for each semaphore array.

example: 2 -> semaphore value, -2 -> sem_undo

Processes are deleted. Linux apply sem_undo.

Semaphore set is deleted. The sem_undo are left on process’s task_struct but the semaphore array identifier is made invalid.

Shared memory l.jpg

Shared Memory

Processes use memory that appears in all of their virtual memory.

No check how the processes are using it.

shm_segs vector

struct shimd_ds {

struct ipc_perm shm_perm ;

int shm_segsz ;// size

time_t shm_atime, shm_dtime, shm_ctime ;

unsigned short shm_cpid, shm_lpid ;

short shm_nattach ;

unsigned short shm_npages ;

unsigned long * shm_pages ;

struct vm_area_struct * attaches ;

} ;

Slide22 l.jpg








Slide23 l.jpg

Each process that wishes to share the memory must attach to that virtual memory via a system call.

create a new vm_area_struct

choose its virtual address / Linux choose

vm_next_shared, vm_prev_shared link them together

The first time that a process accesses one page of the shared virtual memory, a page fault will occur.

Allocate a physical page.

Slide24 l.jpg

no use, detach

Remove its vm_area_struct

process’s page tables are updated to invalidate the area of the memory that it used to share.

The last process

the physical memory are freed

Kernel synchronize l.jpg

Kernel Synchronize

struct wait_queue {

stuct task_struct * task ;

struct wait_queue * next ;

} ;

static inline void add_wait_queue (struct wait_queue

** p, struct wait_queue * wait) {

unsigned long flags ;

save_flags (flags) ;// register flag

cli () ;

__add__wait__queue (p, & wait) ;

restore_flags (flags) ;


Slide26 l.jpg

static inline void remove_wait_queue (struct wait_queue

** p, struct wait_queue * wait) {

unsigned long flags ;

save_flags (flags) ;

cli () ;

__remove__wait__queue (p, & wait) ;

restore_flags (flags) ;


struct semaphore {

int count ;

int waiting ;

struct wait_queue * wait ;

} ;

Slide27 l.jpg

__pseudo__ void down (struct semaphore * psem) {

while (-- psem -> count <= 0) {

psem -> waiting ++ ;

if (psem -> count + psem -> waiting <=0)

do {

sleep_uniteruptible (psem -> wait) ;

} while (psem -> count) ;

psem -> count += psem -> waiting ;

psem -> waiting = 0 ;



Slide28 l.jpg

__pseudo__ void up (struct semaphore) {

if (++ psem -> count <= 0) {

psem -> count += psem -> waiting ;

psem -> waiting = 0 ;

wake_up (psem -> wait) ;



Others l.jpg




  • Login