Process communication IPC

xiaoxiao2021-03-06  42

Two days have learned the communication IPC between UNIX process, which has several important basic concepts, especially the message queue and my trip, so many words.

The process of communication between the previous learning process is generally opened via Fork or EXEC, or by a file system. The IPC is a collective name between the process between processes. The following one will come.

One. pipeline

The pipe is the oldest IPC form. There are two restrictions on the pipe;

(1) They are half-duplex. Data can only flow in one direction.

(2) They can only be used between processes with public ancestors. Typically, a pipe is created by a process, then the process can call fork, then the parent, the child process can apply the pipe.

READ and WRITE can be called to the pipeline descriptor. More beneficial is to copy the pipeline descriptor as standard input and standard output. After this, the child process calls Exec, performs another program, which is written from standard input (the created pipe) or writing data to its standard output (pipeline). This will create some automatic execution programs, such as automatically completing the input from the file, print from the standard output.

A special application: When the same program produces an input of a filter, while reading the output of the filter, the filter is a collaborative process.

two. FIFO named pipe

The pipe can only be used by related processes, and their common ancestors created pipelines. But through FIFO, data can be exchanged.

FIFO is a file type. Creating a FIFO is similar to creating a file, just like using a file.

FIFO has two uses:

(1) FIFO is used by the shell command to transfer the data from a pipeline to another, and there is no need to create an intermediate temporary file.

(2) FIFO is used in the client-server application to pass data between clients and servers.

three. signal

The amount of semapcost is a counter that is used for the access to the shared data object. In order to properly realize the amount of information, the test and minus 1 operation of the signal should be atomic operation. To this end, the amount of signal is usually implemented in the kernel.

There are many introductions about the semaphore, there are not many talks here.

four. Share storage

Shared storage allows two or more processes to share a given storage area, which is the fastest IPC. The most important is to ensure synchronous access to a given storage area. Typically, the amount of semapses (record locks can also be used) are used to implement synchronization of shared storage.

Fives. message queue

The message queue is a message linked table, stored in the kernel and marked by the message queue identifier.

Specific pair of access to the message queue is not more, and here is specially talking about a little skill from the implementation of the message queue from UNIX.

If we add a domain Type in the structure of the message (already existing in UNIX), you can use it to achieve a lot of functions. E.g:

TYPE indicates the type of message, then we can specify a message that receives a Type when receiving a message; or sets Type as a priority value, you can receive messages according to priority, and so on. In this way, we can implement the message queue without following the order of FIFO.

There are a variety of possibilities in CS mode using a message queue:

(1) You can use only one queue between the server and the client, and the TYPE field of each message indicates who is the recipient of the message. For example, a client can send their messages with a type field. In the request, the client's process ID should be included. Thereafter, the server sets the type field as the client's process ID when sending a response message. The server only accepts a message of type 1, and the client only accepts the type field equal to the message ID of their process ID.

(2) Another method is that each client uses a separate message queue. Before sending the first request to the server, each client creates its own message queue. The server also has its own queue, and its identifier is known to all clients. The client will send its first request to the well-known queue of the server, which should include the queue ID of its client message queue. The server sent its first response to the client queue, and all requests and responses have been exchanged on this queue. One problem with this technology is that each client-specific queue typically has only one message (or a request to the server, or respond to the client). This seems to be a waste of limited system resources (message queues), can be replaced with a FIFO. The key points and difficulties of this type of client-server relationship (client and server are unfained processes are: how the server identifies the client to accurately respond.

But for my top, it seems to be in the direction of this message. According to the feature of the GUI, the server receives the external message, and then distributes the correct client after determining the correct customer according to a certain conditional determination. If the customer is handled, it doesn't seem to be a feedback processing result to the server. So what is the so-called "certain condition"? Currently a focus? So what is the message passing between the customer and the customer? What is identified? Is it directly from customers 1 to customers 2, or all messages are forwarded by the server? In the GUI, what is the number of messages?

The most important thing is what I really want to know how to clear the multitasking GUI?

The initial idea is:

1. One server task, each window is a task, only one message queue, maintained by the server, each window only needs to implement its own window procedure to process the message. Then the message queue is global in the GUI system. This seems to be Windows implementation. But at this time, how do I create so many window tasks?

2. A server task, responsible for the main message queue, each window is also a task, but has its own message queue, which is maintained by ourselves. This implementation is more complicated, just like a multi-thread version.

Where is the difference between these two? Can I achieve my function?

转载请注明原文地址:https://www.9cbs.com/read-53670.html

New Post(0)