Skip to content
Snippets Groups Projects
Commit 2c9170a4 authored by iliya's avatar iliya
Browse files

finished ex5, i think?

parent 21547fd2
No related branches found
No related tags found
No related merge requests found
*.o
multi_process
CC := clang
CFLAGS := -g -pedantic -Wall -Wextra -std=c2x
LDFLAGS := -fsanitize=address -fsanitize=leak -fsanitize=undefined -lm
TARGET := multi_process
all: $(TARGET)
$(TARGET): multi_process.o
@printf "=================== Building executable ===================\n"
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
@printf "\n"
%.o: %.c
@printf "================== Building object files ==================\n"
$(CC) $(CFLAGS) -c $<
@printf "\n"
.PHONY: clean
clean:
rm -f *.o $(TARGET)
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#define HOUR_IN_SEC 3600
int main(void) {
pid_t pid = -1;
pid = fork();
if (pid > 0) {
wait(NULL);
fprintf(stdout, "parent(%d)\n", getpid());
fprintf(stdout, "return value of fork: %d\n", pid);
fprintf(stdout, "============= Counter =============\n");
for (int i = 0; i < 50; i++) {
fprintf(stdout, "%d\n", i);
}
fprintf(stdout, "===================================\n");
sleep(HOUR_IN_SEC);
} else if (pid == 0) {
fprintf(stdout, "child(%d)\n", getpid());
fprintf(stdout, "return value of fork: %d\n", pid);
fprintf(stdout, "============= Counter =============\n");
for (int i = 0; i < 50; i++) {
fprintf(stdout, "%d\n", i);
}
fprintf(stdout, "===================================\n");
exit(0);
// sleep(HOUR_IN_SEC);
} else {
perror("fork");
}
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment