aboutsummaryrefslogtreecommitdiff
path: root/semestr-5/so/lista1/rozwiazania/ex2a.c
diff options
context:
space:
mode:
Diffstat (limited to 'semestr-5/so/lista1/rozwiazania/ex2a.c')
-rw-r--r--semestr-5/so/lista1/rozwiazania/ex2a.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/semestr-5/so/lista1/rozwiazania/ex2a.c b/semestr-5/so/lista1/rozwiazania/ex2a.c
new file mode 100644
index 0000000..63b26db
--- /dev/null
+++ b/semestr-5/so/lista1/rozwiazania/ex2a.c
@@ -0,0 +1,25 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+ printf("[%d] Ex2, parent pid: %d\n", getpid(), getppid());
+
+ int pid = fork();
+ if (pid < 0) {
+ printf("Fork error\n");
+ exit(1);
+ }
+ if (pid == 0) {
+ for (int i = 0; i < 10; i++) {
+ printf("[%d] Child process, parent pid: %d\n", getpid(), getppid());
+ sleep(1);
+ }
+ }
+ else {
+ printf("[%d] Sleeping for a second.\n", getpid());
+ sleep(1);
+ printf("[%d] Exit.\n", getpid());
+ exit(0);
+ }
+} \ No newline at end of file