System V and POSIX

Source: Internet
Author: User

System V and POSIX

When we conduct inter-process communication in Linux, such as semaphores, message queues, and shared memory, we will find two types: System V and POSIX. Let's briefly introduce them today.

POSIX:

POSIX (Portable Operating System Interface for Computing Systems) is a cluster of standards developed by IEEE and ISO/IEC. This standard is based on existing UNIX practices and experience. It describes the calling service interfaces of the operating system to ensure that the compiled applications can be transplanted to multiple operating systems at the source code level. It was obtained based on the early work of a UNIX user group (usr/group) in the early 1980 s. The UNIX user group originally attempted to re-reconcile and integrate the differences between the call interfaces of AT&T's System V and Berkeley CSRG's BSD system, thus generating the/usr/group standard in 1984. In 1985, the IEEE Operating System Technical Committee standards Subcommittee (TCOS-SS) began to instruct the IEEE Standards Committee with ANSI support to develop formal standards for program source code portability of operating system service interfaces. In April 1986, IEEE developed a trial standard. The first formal standard was approved in January (IEEE 1003.1-1988) and is also frequently referred to later in POSIX.1.

System V:

System V, also known as AT&T System V, is one of the many Unix operating systems. It was initially developed by AT&T and released for the first time in 1983. A total of four major versions of System V are released: versions 1, 2, 3, and 4. System V Release 4, or SVR4, is the most successful version and becomes the source of Common UNIX features, such as "SysV initialization script" (/etc/init. d), used to control System startup and shutdown. System V Interface Definition (SVID) is a standard Definition of how System V works.
AT&T sells proprietary hardware that runs System V, but many (perhaps most) customers run a resale version on it, based on AT&T's implementation instructions. Popular SysV derivative versions include Dell SVR4 and Bull SVR4. The widely used System V version is SCO OpenServer, which is based on System V Release 3 and SUN Solaris and SCO UnixWare, both of which are based on System V Release 4.
System V is the enhancement of AT&T's first commercial UNIX Version (UNIX System III. Traditionally, System V is regarded as one of two UNIX "Flavors" (BSD ). However, with the emergence of some UNIX implementations that are not based on the two codes, such as Linux and QNX, This induction is no longer accurate, but whatever the case, standardization efforts like POSIX have been trying to reduce the differences between implementations.

Similar to the System V object, the posix ipc object owner, owner group, and other users have read and write permissions, but have no execution permission. The owner of the posix ipc object cannot allocate the object to other owners. Posix ipc provides the following functions:

1. A message allows a process to send formatted data streams to any process. 2. semaphores allow synchronous execution of processes. 3. Shared memory allows the process to share part of its virtual address space.

Unlike the System v ipc interface, the posix ipc interface is a multi-threaded security interface.

Since the IPC of System V has been introduced in previous articles, only the posix ipc interface is described below.

POSIX Message Queue:
API API functions
Mqd_t mq_open (const charName, int oflag, mode_t mode, struct mq_attrAttr) Create a named Message Queue
Mqd_t mq_close (mqd_t mqdes) End the connection to the open Message Queue
Mqd_t mq_unlink (const char * name) End the connection to the open message queue and delete it when the last process closes the queue.
Mqd_t mq_send (mqd_t mqdes, const char * msg_ptr, size_t msg_len, unsigned msg_prio) Put messages into the queue
Ssize_t mq_receive (mqd_t mqdes, charMsg_ptr, size_t msg_len, unsignedMsg_prio) Receive messages in the queue
Mqd_t mq_notify (mqd_t mqdes, const struct sigevent * notification) The notification process or thread message already exists in the queue.
Mqd_t mq_getattr (mqd_t mqdes, struct mq_attrAttr), mqd_t mq_setattr (mqd_t mqdes, struct mq_attrNewattr, struct mq_attr * oldattr) Set or obtain Message Queue attributes
POSIX semaphores:
API API functions
Sem_tSem_open (const charName, int oflag, mode_t mode, unsigned int value) Create named semaphores
Int sem_init (sem_t * sem, int pshared, unsigned int value) Initialize the semaphore Structure
Int sem_close (sem_t * sem) End the connection to the open semaphore
Int sem_unlink (const char * name) End the connection to the open semaphore and delete it when the last process closes the semaphore.
Int sem_getvalue (sem_tSem, intSval) Copy the semaphore value to the specified integer.
Int sem_wait (sem_t * sem) Decrease the semaphores count. When other processes have semaphores, congestion occurs, or an error is returned when other processes have semaphores.
Int sem_post (sem_t * sem) Incremental semaphore count
POSIX shared memory:
API API functions
Int shm_open (const char * name, int oflag, mode_t mode) Create shared memory
Int shm_unlink (const char * name) End the connection to the shared memory and delete it when the last process closes it.
VoidMmap (voidAddr, size_t length, int prot, int flags, int fd, off_t offset) Ing memory

The memory ing mechanism (mmap) is a POSIX standard system call. There are two types of memory ing and file ing:

1. Anonymous ing uses the virtual memory space of the process. It is similar to malloc (). In fact, some malloc implementations use mmap anonymous ing to allocate memory, but anonymous ing is not specified in POSIX standards. 2. There are two types of file ing: MAP_PRIVATE and MAP_SHARED. The former uses the COW method to map the file to the current process space, and the modification operation does not change the source file. The latter directly maps the file to the current process space. All modifications will be directly reflected to the page cache of the file, and then automatically synchronized to the ing file by the kernel.

Compared with IO function calls, a major advantage of file-based mmap is to map the file to the address space of the Process, avoiding data replication from the user buffer to the kernel page cache buffer; of course, there is also an advantage that frequent read/write system calls are not required.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.