-
Notifications
You must be signed in to change notification settings - Fork 606
Expand file tree
/
Copy pathLinux_OS_Pipe_W.cpp
More file actions
38 lines (33 loc) · 839 Bytes
/
Linux_OS_Pipe_W.cpp
File metadata and controls
38 lines (33 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* @Author: xuezaigds@gmail.com
* @Last Modified time: 2016-08-28 16:37:05
*/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <cstdlib>
#include <cstring>
const int SIZE = 1024;
int main(int argc, char *argv[])
{
// 创建匿名管道
if (mkfifo("named_pipe", 0644) == -1){
printf("Create named pipe failed.\n");
exit(-1);
}
printf("Open named pipe with pending modle...\n");
int write_fd = open("named_pipe", O_WRONLY); //打开文件
if (write_fd == -1){
printf("Open named pipe failed!\n");
exit(-1);
}
const char *content = "1111222233334444";
if(write(write_fd, content, strlen(content)) != -1)
{
printf("Write data: \n");
printf("%s\n", content);
}
close(write_fd);
return 0;
}