Practice--linux The Nameless pipes of interprocess communication pipe

Source: Internet
Author: User
Tags posix semaphore

IBM put this system is good, just can the system back to warm up the Linux system knowledge.

http://www.ibm.com/developerworks/cn/linux/l-ipc/part1/

Feel older, the previous years to see the Linux kernel and system, forget a lot, to slowly convert to permanent memory can.

Today, and picked up the "Linux kernel design and implementation", slowly chewing down.

~~~~~~~~~~~~~~

process Communication has some of the following purposes:
A, data transfer: A process needs to send its data to another process, the amount of data sent between a byte to a few m bytes
B, shared data: Multiple processes want to manipulate shared data, a process changes the shared data, and other processes should be seen immediately.
C, notification event: A process needs to send a message to another or a set of processes to notify it (they) that an event has occurred (such as notifying the parent process when the process terminates).
D, resource sharing: Multiple processes share the same resources. In order to do this, the kernel is required to provide a lock and synchronization mechanism.
E, Process Control: Some processes want to fully control the execution of another process (such as the debug process), at which point the control process wants to be able to intercept all the sink and exception of another process and be able to know its state change in time.
the Linux interprocess communication (IPC) has been developed in several parts:
early UNIX interprocess communication, System V based inter-process communication, socket-based interprocess communication, and POSIX interprocess communication.
UNIX inter-process communication methods include: Pipeline, FIFO, signal.
System V interprocess communication methods include: System V Message Queuing, System V Semaphore, System V shared memory,
POSIX interprocess communication includes: POSIX Message Queuing, POSIX semaphore, and POSIX shared memory.
now, the way Linux uses inter-process communication:
(1) piping (pipe) and well-known piping (FIFO)
(2) signal (signal)
(3) Message Queuing
(4) Shared memory
(5) Signal Volume
(6) socket (socket)

~~~~~~~~~~~~~~

Hand-punched code, always reluctant to go:)

/***************** * * readtest.c* * *******************/#include<unistd.h>#include<sys/types.h>#include<errno.h>#include<string.h>#include<stdio.h>#include<stdlib.h>Main () {intpipe_fd[2];    pid_t pid; Charr_buf[ -]; Charw_buf[4]; Char*P_wbuf; intR_num; intcmd; memset (R_buf,0,sizeof(R_BUF)); memset (W_buf,0,sizeof(R_BUF)); P_wbuf=W_buf; if(Pipe (PIPE_FD) <0) {printf ("Pipe Create error\n"); return-1; }        if((Pid=fork ()) = =0) {printf ("\ n"); Close (pipe_fd[1]); Sleep (3); R_num= Read (pipe_fd[0], R_buf, -); printf ("Read num is%d the data read from the pipe is%d\n", R_num, Atoi (R_BUF)); Close (pipe_fd[0]); Exit (1); }    Else if(PID >0) {Close (pipe_fd[0]); strcpy (W_buf,"111"); if(Write (pipe_fd[1], W_buf,4) != -1) {printf ("Parent Write over\n"); } Close (pipe_fd[1]); printf ("parent Close fd[1] over\n"); Sleep (Ten); }}

Practice--linux The Nameless pipes of interprocess communication pipe

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.