diff --git a/lab2/demos/Makefile_bad b/lab2/demos/Makefile_bad new file mode 100644 index 0000000..167f908 --- /dev/null +++ b/lab2/demos/Makefile_bad @@ -0,0 +1,14 @@ +SHELL=/bin/bash +CC=gcc +CFLAGS=-std=c99 -Wall -Wextra -D_POSIX_C_SOURCE=201112L + +.PHONY: all clean + +all: server client + +server: server.c + +client: client.c + +clean: + $(RM) server client diff --git a/lab2/demos/Makefile_good b/lab2/demos/Makefile_good new file mode 100644 index 0000000..a2f0f6c --- /dev/null +++ b/lab2/demos/Makefile_good @@ -0,0 +1,10 @@ +all: server client + +server: server.c + gcc -Wall -Wextra -Werror -D_POSIX_C_SOURCE=201112L -o server server.c + +client: client.c + gcc -Wall -Wextra -Werror -D_POSIX_C_SOURCE=201112L -o client client.c + +clean: + rm -f server client diff --git a/lab2/demos/duplicate_fd.c b/lab2/demos/duplicate_fd.c new file mode 100644 index 0000000..a4ceae5 --- /dev/null +++ b/lab2/demos/duplicate_fd.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +int main(void) { + int fd = open("test.txt", O_CREAT | O_WRONLY); + + if(fd < 0) { + printf("Error opening the file\n"); + } + + dup2(fd, 1); + printf("Tester\n"); + + close(fd); +} diff --git a/lab2/demos/pipe.c b/lab2/demos/pipe.c new file mode 100644 index 0000000..df7edb2 --- /dev/null +++ b/lab2/demos/pipe.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +int main(void) { + char buf[100]; + char msg[] = "Mario"; + + int p[2]; + pipe(p); + + write(p[1], msg, sizeof(msg)); + read(p[0], buf, sizeof(msg)); + + printf("Out from the pipe: `%s`\n", buf); +}