Add lab 2 demos
This commit is contained in:
parent
e359896da0
commit
8d07fc6fef
4 changed files with 58 additions and 0 deletions
14
lab2/demos/Makefile_bad
Normal file
14
lab2/demos/Makefile_bad
Normal file
|
@ -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
|
10
lab2/demos/Makefile_good
Normal file
10
lab2/demos/Makefile_good
Normal file
|
@ -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
|
17
lab2/demos/duplicate_fd.c
Normal file
17
lab2/demos/duplicate_fd.c
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
17
lab2/demos/pipe.c
Normal file
17
lab2/demos/pipe.c
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Reference in a new issue