第十二周预习报告
2015-11-29 17:28
211 查看
exec1
exec2与exec1的区别就在于,execvp函数调用的语句变成了
编译运行结果与exec1.c完全相同,说明arglist数组的第一项为要运行的程序的名称。
exec3.c中给出了一系列的exec函数调用方法,其不同用法如下图所示:
【1.PIPE_BUF的值是多少?】
4096字节
【2.memset函数用法?】
原型:memset(void*s,intch,size_tn);将s中前n个字节用ch替换并返回s
【3.open函数用法?】
open(constchar*pathname,intflags);第一个参数是欲打开的文件路径字符串,第二个参数是打开方式
【4.FIFONAME是什么?】
这里需要补充一下fifo的含义,它是一种文件类型,可以通过查看文件stat结构中的stmode成员的值来判断文件是否是FIFO文件。fifo是用来在进程中使用文件来传输数据的,也具有管道特性,可以在数据读出的时候清除数据。
testpid
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
intmain()
{
printf("mypid:%d\n",getpid());
printf("myparent'spid:%d\n",getppid());
return0;
}
#include<stdio.h> #include<unistd.h> intmain() { char*arglist[3]; arglist[0]="ls"; arglist[1]="-l"; arglist[2]=0;//NULL printf("***Abouttoexecls-l\n"); execvp("ls",arglist); printf("***lsisdone.bye"); return0; }
exec2与exec1的区别就在于,execvp函数调用的语句变成了
execvp(arglist[0],arglist);
编译运行结果与exec1.c完全相同,说明arglist数组的第一项为要运行的程序的名称。
exec3.c中给出了一系列的exec函数调用方法,其不同用法如下图所示:
4.pipe文件夹-consumer.c文件
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<fcntl.h> #include<limits.h> #include<sys/types.h> #include<sys/stat.h> #defineFIFO_NAME"/tmp/myfifo" #defineBUFFER_SIZEPIPE_BUF intmain() { intpipe_fd; intres; intopen_mode=O_RDONLY; charbuffer[BUFFER_SIZE+1]; intbytes=0; memset(buffer,0,sizeof(buffer)); printf("Process%dopeiningFIFOO_RDONLY\n",getpid()); pipe_fd=open(FIFO_NAME,open_mode); printf("Process%dresult%d\n",getpid(),pipe_fd); if(pipe_fd!=-1){ do{ res=read(pipe_fd,buffer,BUFFER_SIZE); bytes+=res; }while(res>0); close(pipe_fd); }else{ exit(EXIT_FAILURE); } printf("Process%dfinished,%dbytesread\n",getpid(),bytes); exit(EXIT_SUCCESS); }
【1.PIPE_BUF的值是多少?】
4096字节
【2.memset函数用法?】
原型:memset(void*s,intch,size_tn);将s中前n个字节用ch替换并返回s
【3.open函数用法?】
open(constchar*pathname,intflags);第一个参数是欲打开的文件路径字符串,第二个参数是打开方式
【4.FIFONAME是什么?】
这里需要补充一下fifo的含义,它是一种文件类型,可以通过查看文件stat结构中的stmode成员的值来判断文件是否是FIFO文件。fifo是用来在进程中使用文件来传输数据的,也具有管道特性,可以在数据读出的时候清除数据。
fifo
生产者和消费者问题testpid
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
intmain()
{
printf("mypid:%d\n",getpid());
printf("myparent'spid:%d\n",getppid());
return0;
}
相关文章推荐
- Android页面跳转动画效果
- 计算机网络---基础题目汇总六
- 四种常见的 POST 提交数据方式
- Thread Pool
- Maven配置自动化部署项目到tomcat
- Get json formatted string from web by sending HttpWebRequest and then deserialize it to get needed data
- HDU-计算机学院大学生程序设计竞赛(2015’11)1003 玩骰子(枚举)
- 解决struts2以GET方式提交表单中文乱码问题
- 大话存储4——RAID磁盘阵列
- Lua封装增加ImageButton接口
- Cocos2D iOS之旅:如何写一个敲地鼠游戏(七):弹出地鼠
- ld: library not found for -lPods-AFNetworking的问题(2015年11月29日更新)
- Cocos2D iOS之旅:如何写一个敲地鼠游戏(七):弹出地鼠
- Cocos2D iOS之旅:如何写一个敲地鼠游戏(七):弹出地鼠
- 下次笑得灿烂点
- hadoop学习005
- DBSet Class(EF基础系列11)
- UNIX网络编程——Posix共享内存区和System V共享内存区
- express添加拦截器
- 为什么抓重点