Справочное Руководство для Intermec ck1

Скачать
Страница из 390
Appendix A — 
µClinux System 
298 
CK1 SDK Programmer’s Reference Manual 
used to identify a System V IPC object. When creating an object, it 
remains in the system memory until it is explicitly removed. The client 
process willing to access to the object has to obtain the objects identifier. 
Each object created has a unique IPC key associated with it, which the 
process has to obtain in order to construct a reference to the object.  
A System V facility queue sends raw data between processes on the same 
machine. When an IPC message is sent, it is placed to the message queue 
where it will stay until the receiving part reads it. When a parent process 
constructs a message it places there an identifier of the destination queue, 
size of the text, and specific type of the message agreed between the 
cooperating processes followed be the message itself. Before the message is 
placed in the queue, the messages user and group identifiers are compared 
with the queue mode to see if the message is allowed to be sent. If allowed, 
the messages are placed into a dynamically allocated memory, at the end of 
this message queue. When reading the message, the processes access rights 
to the queue are checked. The retrieved message may be chosen either to 
get the first message in the queue regardless of its type or to select messages 
with particular types. If match to these criteria is found, the process is 
added to the message queue read wait queue to wait until the type of 
message is received. This action can be done by linking all the messages to 
the next as a linked list.  
A semaphore is an object that manages one or more shared resources. They 
control access to shared data structures for multiple processes. The 
semaphore has a positive value if it is accessible and negative or zero if 
some other process is currently using it. When process wants to access the 
shared resource, it would try to decease the semaphore’s value and if the 
original value is positive, it is allowed to use the resource. Otherwise, if the 
resource is reserved, the process is suspended until the resource allocating 
process is done with it and increment the semaphore’s value back to one. 
Each semaphore object in system V IPC describes a semaphore array, 
which can hold several independent shared data structures. Each process 
with write privileges may make system calls that perform operations on 
them. When inquiring the resource protected by a semaphore, the process 
invokes the identifier of the semaphore with the corresponding IPC key. 
All the semaphores in the array are then tested for an access and, if they 
succeed, the decrements are performed. The kernel applies the operations 
to the appropriate members of the semaphore array. After this, it checks if 
it has suspended processes that may now apply their semaphore operations.  
The deadlock is a situation where two processes are each unknowingly 
waiting for resources held by the other. This holding could happen when a 
process dies without being able to release the semaphore. Linux protects 
these situations with a fail-safe mechanism by maintaining lists of 
adjustments to the semaphore arrays. If the process unexpectedly dies, it is 
able to return all the values from the starting point. 
Shared memory allows one or more processes to access a common data 
structure by placing them into a memory segment shared by all of them. 
The pages of the shared memory are referenced by page table entries in