1
0

feat: Initial commit

This commit is contained in:
2024-03-22 16:54:05 +01:00
parent 0d9957a125
commit d993185b89
25 changed files with 641 additions and 0 deletions

56
Lab05/pipes.c Normal file
View File

@@ -0,0 +1,56 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/wait.h>
void receiver(int fd);
void sender(int fd);
int main() {
int fds[2];
pipe(fds);
if (fork()) {
receiver(fds[0]);
} else if (fork()) {
sender(fds[1]);
}
wait(NULL);
}
void sender(int fd) {
char * str;
int len;
int q = 0;
while (q != EOF) {
q = scanf(" %ms", &str);
len = strlen(str);
printf("%d\n",len);
if (len == 1) break;
write(fd, &len, sizeof(int));
write(fd, str, len);
free(str);
}
close(fd);
}
void receiver(int fd) {
char * str;
int len, q = 0;
while (1) {
q = read(fd, &len, sizeof(int));
if (q == EOF) break;
str = malloc(len * sizeof(char));
q = read(fd, str, len);
if (q == EOF) break;
for (char * c = str; *c != '\0'; c++)
*c = toupper(*c);
puts(str);
free(str);
}
}