#include "common.h"
int a = 100;
static int b = 200;
int main (int argc, char *argv[])
{
pid_t pt = -1;
int c = 300;
static int d = 400;
int *restrict p_e = (int *)malloc(sizeof(int));
*p_e = 500;
printf("-----------------------------process id[%d]--------------------\n", getpid());
pt = fork();
printf("==================process id[%d]=================\n", getpid());
if (pt == -1)
{
err_sys("fork")
}
else if (pt > 0) //parent process
{
sleep(1);
printf("I am parent process[%d], parent process[%d]\n", getpid(), getppid());
printf("parent process[%d] a=%d b=%d c=%d d=%d *p_e=%d\n", getpid(), a, b, c, d, *p_e);
sleep(4);
printf("parent process[%d] a=%p b=%p c=%p d=%p\n", getpid(), &a, &b, &c, &d);
}
else if (pt == 0)
{
printf("I am child process[%d], parent process[%d]\n", getpid(), getppid());
a++;
b++;
c++;
d++;
(*p_e)++;
sleep(2);
printf("child process[%d] a=%p b=%p c=%p d=%p\n", getpid(), &a, &b, &c, &d);
}
printf("+++++++++++++++++++++++++process id[%d]++++++++++++++++++++++++++++++++++++++\n\n\n", getpid());
return 0;
}