2019/01/16

  1. int mkfifo(const char * pathname, mode_t mode)
    pathname:FIFO文件名

  2. 共享内存 (物理内存):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();

  3. 消息队列(在内存中存在):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();

  4. unlink();删除文件。

  5. #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;
    }

  6. #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地址 删除操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值