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&
相关问答:
在linux中,用c或c++,想在程序中使用系统文件/proc/loadavg,里面的实时数据,要怎么读取,有人会吗,我好纠结
严格“实时”有点困难。
可以通过watch命令来定频率获取数据刷新,
watch 'cat /proc/loadavg'
编 ......
tomcat自动重启脚本:
ps -ef | grep tomcat | grep -v grep | sed 's/ [ ]*/:/g' | cut -d: -f3 | kill -9
./startup
请问上面的脚本能不能帮我解释下,谢谢
学习~
你的意思不是太明白,是想自己写 ......
最近想了解下内联汇编,想要用来操作下数组的时候遇到些困难。
我了解到的一些方法:
C/C++ code:
int main()
{
//这种方法可以单独操作数组中的一个
int a[10];
__asm__("movl $10, %0&quo ......
昨天为了解决win与linux的乱码问题,在/etc的sysconfig/i18n里面添加了支持中文的代码,结果变成中文后桌面只能显示背景了,现在几乎只能用终端和上网了,文件夹都无法正常显示(看不到里面的东西),我没有备份系统 ......