我正在尝试编译以下代码,但下面出现错误。 在执行期间如何修改此代码以获取孩子的pid?
代码:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
pid_t fork (void);
pid_t pid;
pid = fork();
错误:
> bash-4.3# gcc testFirstPartFork.c testFirstPartFork.c:9:1: warning:
> data definition has no type or storage class pid = fork();
^
> testFirstPartFork.c:9:1: warning: type defaults to 'int' in
> declaration of 'pid' [-Wimplicit-int] testFirstPartFork.c:9:7: error:
> initializer element is not constant pid = fork();