CSAPP第八章家庭作业参考答案

CSAPP第⼋章家庭作业参考答案(CSAPP第三版系列)
宁码输入法8.12 这个程序输出多少个“hello”输出⾏?
分析该程序doit()函数的⾏为,4个进程都会再返回到主程序,所以程序会输出8个“hello”输出⾏。
8.16 下⾯这个程序的输出是什么?
分析该程序,⼦进程将count减⼀,⽗进程将其加⼀后输出,所以输出是: counter = 1。
8.20使⽤execve编写⼀个叫做myls的程序,该程序的⾏为和/bin/ls程序的⼀样。
除冰车
程序如下:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
连供系统int main(int argc,char *argv[],char *envp[])
{
if(execve("/bin/ls",argv,envp) == -1)
printf("execve error!\n");
return 0;
}
测试结果如下:
8.24 修改图8-18中的程序。
程序如下:
#include <unistd.h>
#include <sys/types.h>
废盐焚烧炉选型#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#define N 2
int main()
{
int status,i;
pid_t pid;
电子管话筒
for(i = 0;i < N;i++)
if((pid = fork()) == 0)
{
int *pt = 0x0;
*pt = 15213;
exit(100+i);
}
while((pid = waitpid(-1,&status,0)) > 0)
{
if(WIFEXITED(status))
printf("child %d terminated normally with exit status = %d\n",pid,WEXITSTATUS(status));  else if(WIFSIGNALED(status))
{
fprintf(stderr,"child %d terminated by signal %d",pid,WTERMSIG(status));
海水淡化装置psignal(WTERMSIG(status)," ");
}
else
printf("child %d terminated abnormally\n",pid);
}
if(errno != ECHILD)
printf("waitpid error\n");
exit(0);
}
测试结果如下:

本文发布于:2024-09-22 16:42:10,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/1/197426.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:程序   输出   选型   装置   家庭作业
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议