Add your Comment
Linux processes are best explained by a program.
1.write a program to create a process
can malloc allocated before fork can print same address in parent and child
#include<stdio.h>
#include<malloc.h> /malloc header
#include<unistd.h> /fork header
int main()
{
int *p =(int *)malloc(sizeof(int));
printf(“we are in main \n”);
printf(“value of p is–%p \n”,p);
pid_t pr = fork();
if( pr == 0 )
{
printf(“we are in child \n”);
printf(“value of p is–%p \n”,p);
}
else if( pr > 0 )
{
printf(“we are in parent \n”);
printf(“value of p is–%p \n”,p);
}
return 0;
}
Output:-
we are in main
value of p is–0x1226c010
we are in parent
value of p is–0x1226c010
we are in child
value of p is–0x1226c010
SEE ALL
YOU
