Process learning pipeline and message queue in UNIX

Source: Internet
Author: User

In UNIX, the multi-process zombie process in the process learning pipeline and Message Queue linux has been terminated, but has not been cleared from the Progress table. If the child process is terminated before the parent process, and the parent often does not call wait to receive information about the child process, the child process will be converted into a zombie process until the parent process ends. Avoid zombie process method 1) the wait parent process actively calls wait (or calls it after receiving the signal) to receive the death report of the child process and release the system progress table resources occupied by the child process. 2) If the parent process dies before the child process, all its child processes are switched to the init process for adoption. 3) the SIGC (H) LD signal is ignored when the parent process ignores this signal, even if you do not run wait, the child process does not end with a zombie process. 4) Capture SIGC (H) LD signal parent process capture SIGC (H) LD signal, and wait for wait sub-process in the capture function. the daemon is a process that runs on the background for a long time. It is independent of the control terminal and periodically executes a task. the preparation of a daemon includes at least the following items: 1) The execution of the prepare method in the background; 2) the independent control terminal setsid (); 3) the clear file creation mask umask (0); 4) there are limits on UNIX for ipcs to delete IPAC object ipcrmIPC in signal query, for example, maximum number of bytes in message queue. maximum number of semaphores. you can change the kernel parameters. www.2cto.com inter-process communication pipeline Message Queue semaphore shared memory pipeline: Unknown pipeline: int pipe (int fildes [2]) in UNIX, functions for creating unknown pipelines include pipe, popen: The pclose function is used to close the nameless pipeline. create mknod and mkfifo, and create mkfifo. the unknown MPs queue is applied to the parent Sub-processes. A famous pipeline is stored in external storage devices such as disks as files and can be applied in any two processes. the message queue ipcs-a-q currently has two types of Message Queues: POSIX message queues and System V message queues. The System V message queues are currently widely used. Considering the portability of applications, newly developed applications should use POSIX message queues whenever possible. The System V Message Queue continues with the kernel. It is deleted only when the kernel restarts or explicitly deletes a message queue. Therefore, the data structure (struct ipc_ids msg_ids) of the Message Queue recorded in the system is located in the kernel. All message queues in the system can find the access entry in the msg_ids structure. A message queue is a linked list of messages. Each message queue has a queue header, which is described by the structure struct msg_queue. The queue header contains a large amount of information about the message queue, including the key value, user ID, group ID, and number of messages in the message queue, the ID of the read/write process of the message queue. Readers can access this information, you can also set some information in the message queue to a first-in-first-out linked list structure in the UNIX kernel. UNIX uses the msgid_s structure to manage the creation of the Message Queue www.2cto.com int msgget (key_t key, int msgflag) int msgsnd (int msgid, void * msgp, int msgsz, int msgflg) Message Queue receives int msgrcv (int msgid, void * msgp, int msgsz, long msgtype, int msgflg) Message Queue controls int msgctl (int msgid, int cmd, struct msgid_ds * buf) Message Queue communication is more flexible than pipeline communication. the communication process does not have the kinship requirement, nor does it need to be synchronized. the sending process can write messages at any time or end execution before receiving messages. pipeline, whether it is an unknown pipeline or a famous Pipeline, both processes of communication must be running.
Message Queue is a type of IPC object. It has the following features compared with the pipeline that provides the first-in-first-out service. 1) Message Queue provides the automatic splitting function of message data, messages cannot be received twice at the same time. 2) A Message Queue provides services that are not completely read randomly. After a message type is introduced, a queue can be logically considered as a linked list of different message types, you can choose to receive messages from a logical linked list instead of the first message in the queue. 3) The Message Queue provides a completely asynchronous read/write service. When using the MPs queue, both read and write ends must be opened at the same time. Without this restriction, the process can open the MQ at any time, you can also read messages that do not exist from the queue. msgget is used to create a message queue, msgsnd is used to send a message queue, msgrcv is used to receive messages from a message queue, and msgctl is used to control message queues, it can query the data structure of message queues, change the access permissions of message queues, change the owner information of message queues, and delete message queues.
Author felixit0120

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.