mirror of
https://github.com/epasveer/seer.git
synced 2026-08-29 08:34:42 +08:00
Test program for forks.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user