Linux 下实现两个管道双向数据流
原文地址:http://www.wangzhongyuan.com/archives/488.html
以下是一个Linux/Unix下由两个管道提供双向数据流的C程序,这是操作系统课程中经常使用的基本程序
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <string.h>
int main()
{
int fd1[2],fd2[2],cld_pid,status;
char buf[200], len;
if (pipe(fd1) == -1) // 创建管道1
{
printf("creat pipe1 error\n");
exit(1);
}
if (pipe(fd2) == -1) // 创建管道2
{
printf("creat pipe2 error\n");
exit(1);
}
if ((cld_pid=fork()) == 0) //子进程
{
close(fd1[1]); // 子进程关闭管道1的写入端
close(fd2[0]); // 子进程关闭管道1的读出端
//子进程读管道1
len = read(fd1[0],buf,sizeof(buf));
printf("\n这是在子进程:子进程从管道1中读出的字符串 -- %s",buf);
//子进程写管道2
strcpy(buf,"子进程写入管道2的字符串");
write(fd2[1],buf,strlen(buf));
printf("\n这是在子进程:子进程成功写入如下语句:%s\n",buf);
exit(0);
}
else //父进程
{
close(fd1[0]); // 父进程关闭管道1的读出端
close(fd2[1]); // 父进程关闭管道2的写入端
//父进程写管道1
strcpy(buf,"父进程写入管道1的字符串");
write(fd1[1],buf, strlen(buf));
printf("miaojing\n");
//父进程读管道2
len = read(fd2[0],buf,sizeof(buf));
printf("\n这是在父进程:父进程从管道2中读出的字符串 -- %s\n",buf);
exit(0);
}
}
相关文档:
例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......
3、PHP安装
1)还是下载源码包,如:php-5.1.1.tar.gz,下载地址:http://www.php.net
2)解压缩,>tar -zxvf php-5.1.1.tar.gz
3)进入php-5.1.1,>cd php-5.1.1
4)安装配置,>./configure --prefix=/opt/php
--with-apxs2=/opt/apache/bin/apxs --with-mysql=/opt/mysql
--with-mysqli=/opt/mysql/bin/ ......
RPM有5种基本操作模式(不包括软件包建构):安装、删除、升级、查询和校验。
RPM包的名称格式,eg:caleng-1.0-1.i386.rpm。该文件名包括软件包名称“caleng”;软件版本号“1.0“,其中包括主版本号和次版本号;"i386"是软件所运行的硬件平台。
1、安装RPM包,eg: $>rpm -ivh test.rp ......
原文地址:http://www.wangzhongyuan.com/archives/487.html
以下是一个Linux/Unix下显示某一目录下文件列表的C程序,相当于最基本的ls命令的功能,显示的内容报告该目录下的子目录以及文件名:
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
int m ......