Linux FIFO代码问题 - Linux/Unix社区 / 程序开发区
/*speak.c*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define FIFO_NAME "american_maid"
int main(void)
{
char s[300];
int num, fd;
mknod(FIFO_NAME, S_IFIFO | 0666, 0);
printf("waiting for readers...\n");
fd = open(FIFO_NAME, O_WRONLY);
printf("got a reader--type some stuff\n");
while (gets(s), !feof(stdin)) {
if ((num = write(fd, s, strlen(s))) == -1)
perror("write");
else
printf("speak: wrote %d bytes\n", num);
}
return 0;
}
/*tick.c*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define FIFO_NAME "american_maid"
int main(void)
{
char s[300];
int num, fd;
mknod(FIFO_NAME, S_IFIFO | 0666, 0);
printf("waiting for writers...\n");
fd = open(FIFO_NAME, O_RDONLY);
printf("got a writer\n");
do {
if ((num = read(fd, s, 300)) == -1)
perror("read");
else {
s[num] = '\0';
printf("tick: read %d bytes: \"%s\"\n&
相关问答:
引用内容vsking 2009-12-25 22:56:52
现在是win2008和iis8的时代了,不要还停留在iis5时代,win2008被评为十佳操作系统之首不是偶然的,你要是..
我的问题是:
最近想买个服务器,看了dell上的系统定制选择,一些 ......
现在需要在一个嵌入式系统中实现时间函数,编译器未提供time库函数,请问大家如何用c语言实现时间函数啊?
年月日时分秒 到 整数秒(从1970年开始) 之间的相关转换啊
类似mktime 和localtime的功能,谢谢
mktime ......
rt,我试了网上直连Acces数据库的方法,windows下没有问题,但是在linux下不行,谁能给点提示?谢谢
你怎么连的?
Acces数据库..
你怎么练的呢?
Java code:
static String DBDRIVER = "sun.jd ......
大家好,我现在正在学习linux系统,碰到点问题想请问大家,希望前辈能够指教。
在linux中为什么我用shutdown -r now 命令来重启系统没有用呢,而reboot命令就可以。
另外我也试过#shutdown -r now 和
shutdow等命 ......
tomcat自动重启脚本:
ps -ef | grep tomcat | grep -v grep | sed 's/ [ ]*/:/g' | cut -d: -f3 | kill -9
./startup
请问上面的脚本能不能帮我解释下,谢谢
学习~
你的意思不是太明白,是想自己写 ......