--- In [email protected], Sudipta Deb <dsudipta.1...@...> wrote:
>
> How can i print parent's PID from child's and vice versa.

int main(void)
{
    pid_t       pidParent, pidChild = fork();
    const char *who;

    if (pidChild == 0)
    {
        who       = "child";
        pidChild  = getpid();
        pidParent = getppid();
    }
    else
    {
        who       = "parent";
        pidParent = getpid();
    }

    printf("%s: child=%d\n", who, pidChild);
    printf("%s: parent=%d\n", who, pidParent);

    return 0;
}

child: child=4968
child: parent=4967
parent: child=4968
parent: parent=4967


Reply via email to