You are on page 1of 1

#include <stdio.

h>
#include <sys/types.h>
#include <unistd.h>

void P2(pid_t pid, int arg); /* child process prototype */


void P1(pid_t pid); /* parent process prototype */

void main(void)
{
pid_t pid;
int arg;
printf("Enter number: ");
scanf("%d", &arg);

pid = fork();
if (pid == 0)
{
P2(pid, arg);
P1(pid);
}
}

void P2(pid_t pid, int arg)


{
printf("Children PID: %d\n", pid);

for (int i = 1; i <= 10; ++i) {


printf("%d * %d = %d \n", arg, i, arg * i);
}
}

void P1(pid_t pid)


{
printf("P1 is running!\n");
printf("P2 PID: %d\n", pid);
printf("P2 is done!");
}

You might also like