按关键词阅读: 考核 期末 汇总 题目
最后父进程执行wait() 。
P225 7.5#include#include#inclu 。
10、de#include#include#includeint main()pid_t pid;
int fd;
char *buf1=(char *)malloc(20);
char *buf2=(char *)malloc(20);
strcpy(buf1,this is child process:);
strcpy(buf2,this is parent process:);
if(fd=open(file,O_CREAT|O_RDWR)#include#include#include#include#includeint main()pid_t pid;
int fd;
char *buf1=(char 。
11、 *)malloc(20);
char *buf2=(char *)malloc(20);
strcpy(buf1,this is child process:);
strcpy(buf2,this is parent process:);
if(fd=open(file,O_CREAT|O_RDWR)#include#include#include#include#includeintmain()intfd=-1;
fd=open(zhidao_561804018.dat,O_CREAT|O_TRUNC|O_RDWR,0666);
if(fd0)close(fd);
fd=-1;
return0;
6、 首先 。
12、建立一个守护进程 , 然后让该守护进程每隔10s在/tmp/dameon.log中写入一句话#include #include #include #include #include #include #include #define MAXFILE 65535int main(void)pid_t pc;
int i,fd,len;
char *buf=This is a Dameonn;
len=strlen(buf);
pc=fork();
if(pc0)exit(0);
setsid();
chdir(/);
umask(0);
for(i=0;
i#include #include void my_op(in 。
13、t);
main()sigset_t new_mask;
struct sigaction act;
sigemptyset(&act.sa_mask);
act.sa_flags=0;
act.sa_handler=my_op;
if(sigaction(SIGINT,&act,NULL) /注册信号SIGINT处理函数为my_opprintf(install signal SIGINT errorn);
if(sigaction(SIGQUIT,&act,NULL) /注册信号SIGQUIT处理函数为my_opprintf(install signal SIGQUIT errorn);
printf(pl 。
【期末|期末考核题目汇总】14、ease send signal: kill -s %d %dn,SIGQUIT, getpid();
sigemptyset(&new_mask);
if(sigprocmask(0, NULL,&new_mask) 0) /查询当前进程被挂起的信号存入new_mask中 , /可用sigpending(&new_mask)代替printf(get pending mask errorn);
sigaddset(&new_mask,SIGQUIT);
/将信号SIGQUIT , 添加到信号集new_mask中 , /也就是在原有的信号掩码中加入信号SIGQUIT 。
sigsuspend(&new_mask);
/将当前的信号掩码替换成new_mask , /也就是把信号SIGQUIT给阻塞后 , 当前进程挂起 。
/必须等待除了未阻塞的信号到来才恢复成原来的信号掩码exit(0);
void my_op(int signum)if ( signum = SIGINT )printf(SIGINTn);
else if ( signum = SIGQUIT )printf(SIGQUITn);
return 。

稿源:(未知)
【傻大方】网址:/a/2021/0801/0023374107.html
标题:期末|期末考核题目汇总( 二 )