summaryrefslogtreecommitdiff
path: root/user/fork.c
diff options
context:
space:
mode:
Diffstat (limited to 'user/fork.c')
-rw-r--r--user/fork.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/user/fork.c b/user/fork.c
new file mode 100644
index 0000000..d534fcf
--- /dev/null
+++ b/user/fork.c
@@ -0,0 +1,20 @@
+#include <unistd.h>
+#include <stdio.h>
+
+int main(void)
+{
+ printf("im going to print some a's and b's. get ready\n");
+
+ int pid = fork();
+ if (pid < 0) {
+ fprintf(stderr, "fork failed!\n");
+ return 1;
+ }
+
+ for (int i = 0; i < 10; i++) {
+ putchar(pid == 0 ? 'a' : 'b');
+ putchar('\n');
+ }
+
+ return 0;
+}