41 lines
620 B
C++
41 lines
620 B
C++
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int fd;
|
|
int ret;
|
|
|
|
ret = mkfifo("my_fifo", 0666);
|
|
if(ret != 0)
|
|
{
|
|
perror("mkfifo");
|
|
}
|
|
|
|
printf("before open\n");
|
|
fd = open("my_fifo", O_WRONLY); //等着只读
|
|
if(fd < 0)
|
|
{
|
|
perror("open fifo");
|
|
}
|
|
|
|
printf("after open\n");
|
|
|
|
|
|
sleep(5);
|
|
char send[100] = "100";
|
|
write(fd, send, strlen(send));
|
|
printf("write to my_fifo buf=%s\n", send);
|
|
while (1)
|
|
{
|
|
/* code */
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
} |