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&
相关问答:
写了个测试程序如下
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
......
咨询QQ:269562808
bzip2recover
功能说明:用来修复损坏的.bz2文件。
语法:bzip2recover[.bz2压缩文件]
补充说明:bzip2是以区块的方式来压缩文件,每个区块视为独立的单位。因此,当某一区
块损坏时,便可利 ......
现在需要在一个嵌入式系统中实现时间函数,编译器未提供time库函数,请问大家如何用c语言实现时间函数啊?
年月日时分秒 到 整数秒(从1970年开始) 之间的相关转换啊
类似mktime 和localtime的功能,谢谢
mktime ......
在linux中,用c或c++,想在程序中使用系统文件/proc/loadavg,里面的实时数据,要怎么读取,有人会吗,我好纠结
严格“实时”有点困难。
可以通过watch命令来定频率获取数据刷新,
watch 'cat /proc/loadavg'
编 ......
各位大虾,先问声好!
想请教一下在window下用putty怎么部署linux服务器上的SSH框架,数据库和tomcat都安装好了,jdk也装上去了,现在就是怎么在上面搭建SSH框架了!求各位不吝赐教!或者提供相应 ......