28 lines
483 B
C
28 lines
483 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/wait.h>
|
|
|
|
int main(){
|
|
int fd, pid, n;
|
|
char buf[10];
|
|
|
|
fd = open("test.txt", O_RDWR);
|
|
pid = fork();
|
|
|
|
if(pid == 0){
|
|
write(fd, "FOXLIVER", O_RDWR);
|
|
close(fd);
|
|
exit(0);
|
|
}else{
|
|
wait(0);
|
|
lseek(fd, 0, SEEK_SET);
|
|
n = read(fd, buf, 9);
|
|
buf[n] = '\0';
|
|
printf("%s \n", buf);
|
|
close(fd);
|
|
}
|
|
|
|
return 0;
|
|
} |