IPC File communication

This commit is contained in:
2025-09-25 15:57:35 +09:00
parent 1fdc890506
commit 1a495e3e63

28
Practice_06/ipcFile.c Normal file
View File

@@ -0,0 +1,28 @@
#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;
}