I have a C program that forks, which I'm running from a linux bash shell.
Problem:-After forking Not geetting expected output.
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
void main(){
pid_t p1;
int size;
char *new;
char test[2]={'\0'};
int arr[5]={1,2,3,4,5};
printf("\nIn Parent process");
printf("\nElements of Array are:");
for(int i=0;i<5;i++) {
printf("%d ",arr[i]);
}
p1=fork();
if(!p1) {
printf("\nIn child Process");
}
wait(NULL);
}
actual result
In Parent process
Elements of Array are:12345
In child ProcessElements of Array are:12345
desired output:-
In Parent process
Elements of Array are:12345
In child Process