1.熟悉wc命令
wc命令用于计算文件的Byte数、字数、或是列数,若不指定文件名称、或是所给予的文件名为"-",则wc指令会从标准输入设备读取数据。
参数:
c或--bytes或--chars 只显示Bytes数。
-l或--lines 只显示行数。
-w或--words 只显示字数。
--help 在线帮助。
--version 显示版本信息
2.进程通信
输入“su”后输入密码以便一下操作。
(1)读管道
gedit pip_read.c
打开文件后输入:
#include <unistd.h> #include <stdlib. h> #include <stdio.h> #include <str ing.h> int main(){ FILE *read_ fp; //文件流指针 char buffer [BUFSIZ+1]; //存储读取的内容 int chars_ read; nenset(buffer, ' ' ,sizeof(buffer)); //初始化buf ,以免后面乱码到文件中 read_ _fp=popen("unane -a","r"); //只读方式打开连接到uname命令的管道,只读方式说明:可以通过stdio 的库函数fread 读取被调用程序的输出 if(read_ _fp!=NULL){ chars_ read=fread(buffer ,sizeof(char) , BUFSIZ,read_ fp); if(chars_ read>0 ) printf("output was:- %s " ,buffer); pclose(read_ fp); //关闭管道 exit( EXIT_ SUCCESS); //正常退出
} exit(EXIT_ FAILURE); //读取失败
}
运行截图:
(2)写管道
输入命令“gedit pip_write.c”打开文件后输入:
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> int main()[ *write_fp; char buffer [BUFSIZ+1]; int chars_write; memset(buffer, '