作业
作业一:
int main(int argc, const char *argv[])
{
pid_t pid=fork();
if(pid>0)
{
int fd=open("./01.txt",O_WRONLY|O_TRUNC|O_CREAT,0664);
char buf[64]={0};
int bkg=dup(STDOUT_FILENO);
dup2(fd,STDOUT_FILENO);
scanf("%s",buf);
printf("%s",buf);
fflush(stdout);
dup2(bkg,STDOUT_FILENO);
close(fd);
}
if(pid==0)
{
sleep(5);
int fd1=open("./01.txt",O_RDONLY);
char str[64]={0};
read(fd1,str,63);
printf("%s",str);
close(fd1);
}
return 0;
}
作业二:
int main(int argc, const char *argv[])
{
pid_t pid=fork();
if(pid>0)
{
execl("./03"," ",NULL);
}
else if(pid==0)
{
sleep(10);
char *arg[3]={"03"," ",NULL};
execv("./03",arg);
}
return 0;
}
int main(int argc, const char *argv[])
{
system("find /usr -name include");
return 0;
}
思维导图: