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);
}
}
相关文档:
4、mcrypt安装
1)安装mcrypt之前,必须安装libmcrypt和mhash,先去http://www.sourceforge.net
下载Libmcrypt,mhash,mcrypt安装包
2)先安装Libmcrypt
>tar -zxvf libmcrypt-2.5.8.tar.gz
>cd libmcrypt-2.5.8
>./conf ......
假设php安装在/usr/local/php5/bin/php,初始在命令行执行PHP的时候要输入一长串的路径,eg:
$>/usr/local/php5/bin/php phpinfo.php
非常的麻烦,现在只需将php拷贝至usr/sbin目录即可直接使用php命令,eg:
$>cp /usr/local/php5/bin/php /usr/sbin/
$>php phpinfo.php
......
RPM有5种基本操作模式(不包括软件包建构):安装、删除、升级、查询和校验。
RPM包的名称格式,eg:caleng-1.0-1.i386.rpm。该文件名包括软件包名称“caleng”;软件版本号“1.0“,其中包括主版本号和次版本号;"i386"是软件所运行的硬件平台。
1、安装RPM包,eg: $>rpm -ivh test.rp ......
一。linux系统的默认编码设置。
/etc/sysconfig/i18n
Controls the system font
settings. The language variables are used in /etc/profile.d/lang.sh. An
example i18n file:
LANG="zh_CN.GB18030"
LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"
SUPPORTED="zh_CN.GB18030:zh_CN ......
linux系统root用户可强制踢制其它登录用户,
首先以root登录以便查看全部的在线用户信息,可用w命令查看登录用户信息
强制踢人命令格式:pkill -kill -t tty
解释:
pkill -kill -t 踢人命令
tty 所踢用户的TTY
如上踢出liu用户的命令为: pkill -kill -t pts/1
......