hi im quiet new to c programing so i wonderd if i could get some help on this code
Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int Child(int z);
int Parent(int y);
int main()
{
int x; /* pid storage for later use*/
int z; /*returned pid value*/
int y; /*returned pid value*/
x = getpid(); /* insert parent id into x for later use */
printf("First pid is %d\n", x); /* shows id of verry first proccess */
pid_t pid;
pid = fork();
if (pid == 0)
Child(z);
else
Parent(y);
pid = wait();
printf("FirstP, Child pid is %d\n", z);
printf("FirstP, Parent pid is %d\n", y);
}
int Child(int z)
{
z = getpid(); /*stores pid to be returned*/
printf("child pid is %d\n", getpid());
return z;
}
int Parent(int y)
{
y = getpid(); /*stores pid to be returned*/
printf("parent pid is %d\n", getpid());
return y;
}
i cant get " z and y" to print out the correct pid from the Child() and Parent() function when returned to main. could someone tell me what im missing here?
this is what it throws out after being run
Code:
First pid is 6233
parent pid is 6233
child pid is 6234
FirstP, Child pid is 134514025
FirstP, Parent pid is -1076644744
FirstP, Child pid is 134514025
FirstP, Parent pid is -1076644744