IPC File communication
This commit is contained in:
28
Practice_06/ipcFile.c
Normal file
28
Practice_06/ipcFile.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user