-
int mkfifo(const char * pathname, mode_t mode)
pathname:FIFO文件名 -
共享内存 (物理内存):1.创建(获取)共享内存,shmget(), int shmget ( key_t key, int size, int shmflg );2.映射 shmat(),char * shmat ( int shmid, char *shmaddr, int flag); 3.使用共享内存;4.解除共享内存,shmdt(); 5.删除共享内存,shmctl();
-
消息队列(在内存中存在):1.创建消息队列(获取)megget();2.读写消息队列 msgsnd(),int msgsnd(int msqid,struct msgbuf*msgp,int msgsz,int msgflg);
msgrcv(),int msgrcv(int msqid, struct msgbuf *msgp, int msgsz, long msgtyp, int msgflg);3.删除消息队列 msgctl(); -
unlink();删除文件。
-
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
int main()
{
pid_t pid;
scanf("%d", &pid);//kill(pid, 2);
//kill(pid, SIGKILL);
raise(2); //给进程本身发送信号
while (1);return 0;
} -
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
int main()
{
int ret, fd;
char buf[32] = {0};ret = mkfifo(“fifo.tmp”, 00700); //创建有名管道文件
if (-1 == ret)
{
perror(“mkfifo”);
exit(1);
}fd = open(“fifo.tmp”, O_RDONLY); //只读方式打开管道文件
if(-1 == fd)
{
perror(“open”);
exit(1);
}while (1)
{
ret = read(fd, buf, sizeof(buf));
if (-1 == ret)
{
perror(“read”);
}
if (!strcmp(buf, “bye”))
{
break;
}printf("%s\n", buf); memset(buf, 0, sizeof(buf));
}
close(fd);
unlink(“fifo.tmp”); //删除管道文件return 0;
}
7 .#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int fd, ret;
char buf[32] = {0};
fd = open("fifo.tmp", O_WRONLY); //只写的方式打开管道文件
if (-1 == fd)
{
perror("open");
exit(1);
}
while (1)
{
scanf("%s", buf);
ret = write(fd, buf, strlen(buf));
if (-1 == ret)
{
perror("write");
}
if (!strcmp(buf, "bye"))
{
break;
}
memset(buf, 0, sizeof(buf));
}
close(fd);
return 0;
}
8. 信号量:1.创建(获取信号量/集),semget();2.初始量信号量(二值信号量、计数),semctl();3.pv操作,semop();4.删除信号量 semctl();
9. ipcs -m 查看共享内存ip,ipcrm -m ip地址 删除操作。