返回值:
A value of zero to the child process; and the process ID of the child process to the parent process.
Both processes continue to execute from the fork() function. If an error occurs, fork() returns -1 to the parent and sets errno.
#include <sys/types.h>
#include <process.h> int main()
{
pid_t pid;
puts("<1>");
pid=fork(); if (pid <0) {
printf("error in fork! \r\n");
} elseif (pid ==0) {
printf("i am the child process, my process id is %d \r\n",getpid());
} else {
printf("i am the parent process, my process id is %d \r\n",getpid());
}