Test program for forks.

This commit is contained in:
Ernie Pasveer
2022-04-18 15:50:29 -05:00
parent 09aeb23496
commit d35938fa39
2 changed files with 32 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
# This is the default target, which will be built when
# you invoke make
.PHONY: all
all: hellofork
hellofork: hellofork.c
g++ -g -o hellofork hellofork.c
.PHONY: clean
clean:
rm -f hellofork hellofork.o
+20
View File
@@ -0,0 +1,20 @@
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
void func(int pid, int ret)
{
printf("My PID is %d, fork() returned %d\n", pid, ret);
if (ret)
printf("We are in the parent process\n");
else
printf("We are in the child process\n");
}
int main()
{
int r = fork();
func(getpid(), r);
return 0;
}