feat: update structure

This commit is contained in:
2024-01-22 14:27:40 +08:00
parent 7836c9185c
commit 3544a28a2e
559 changed files with 120846 additions and 4102 deletions

24
cs2106/lectures/l5/3.c Normal file
View File

@@ -0,0 +1,24 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#define READ_END 0
#define WRITE_END 1
int main() {
int pipeFd[2], pid, len;
char buf[100], *str = "Hello There!";
pipe(pipeFd);
if ((pid = fork()) > 0) {
close(pipeFd[READ_END]);
write(pipeFd[WRITE_END], str, strlen(str) +1);
close(pipeFd[WRITE_END]);
} else {
close(pipeFd[WRITE_END]);
len = read(pipeFd[READ_END], buf, sizeof(buf));
printf("Proc %d read: %s\n", pid, buf);
close(pipeFd[READ_END]);
}
}