#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/wait.h>
int main(int argc, const char *argv[])
{
int fd=open("demo1.txt",O_CREAT|O_WRONLY,0664);
if(-1==fd)
{
return 0;
}
pid_t res=fork();
if(res>0)
{
char str[32];
scanf("%s",str);
write(fd,str,strlen(str));
close(fd);
}
else if(res==0)
{
sleep(3);
int fd1=open("demo1.txt",O_RDONLY);
char a;
while(1)
{
int res=read(fd1,&a,1);
if(res==0)break;
putchar(a);
}
putchar(10);
close(fd1);
}
return 0;
}
day4IO作业
最新推荐文章于 2024-09-19 11:53:12 发布