UNIX环境高级编程——进程间通讯方法整理
一.无名管道pipe
#include <unistd.h> int pipe(int fd [2])
二.fifo
#include <sys/stat.h> int mkfifo(const char *path, mode_t mode);
三.信号
#include <signal.h> void (*signal(int sig, void (*func)(int)))(int);
#include <signal.h> int sigaction(int sig, const struct sigaction *restrict act,struct sigaction *restrict oact);
#include <signal.h> int kill(pid_t pid, int sig);
#include <signal.h> int raise(int sig);
#include <signal.h> int sigqueue(pid_t pid, int signo, const union sigval value);
#include <unistd.h> unsigned alarm(unsigned seconds);
#include <stdlib.h> void abort(void);
四.消息队列
#include <sys/msg.h> int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
#include <sys/msg.h> ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp,int msgflg);
#include <sys/msg.h> int msgget(key_t key, int msgflg);
#include <sys/msg.h> int msgctl(int msqid, int cmd, struct msqid_ds *buf);
五.信号量
#include <sys/ipc.h> key_t ftok(const char *path, int id);
#include <sys/sem.h> int semget(key_t key, int nsems, int semflg);
#include <sys/sem.h> int semop(int semid, struct sembuf *sops, size_t nsops);
#include <sys/sem.h> int semctl(int semid, int semnum, int cmd, ...);
六.共享内存
#include <sys/shm.h> int shmget(key_t key, size_t size, int shmflg);
#include <sys/shm.h> void *shmat(int shmid, const void *shmaddr, int shmflg);
#include <sys/shm.h> int shmdt(const void *shmaddr);
#include <sys/shm.h> int shmctl(int shmid, int cmd, struct shmid_ds *buf);
七.socket
#include <sys/socket.h> int socket(int domain, int type, int protocol);
#include <sys/socket.h> int bind(int socket, const struct sockaddr *address,socklen_t address_len);
#include <sys/socket.h> int connect(int socket, const struct sockaddr *address,socklen_t address_len);
#include <sys/socket.h> int accept(int socket, struct sockaddr *restrict address,socklen_t *restrict address_len);
#include <sys/socket.h> ssize_t recv(int socket, void *buffer, size_t length, int flags);
#include <sys/socket.h> ssize_t recvfrom(int socket, void *restrict buffer, size_t length,int flags, struct sockaddr *restrict address,socklen_t *restrict address_len);
#include <sys/socket.h> ssize_t recvmsg(int socket, struct msghdr *message, int flags);
#include <sys/socket.h> ssize_t send(int socket, const void *buffer, size_t length, int flags);
#include <sys/socket.h> ssize_t sendto(int socket, const void *message, size_t length,int flags, const struct sockaddr *dest_addr,socklen_t dest_len);
#include <sys/socket.h> ssize_t sendmsg(int socket, const struct msghdr *message, int flags);