Embed presentation
Download to read offline
![#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#define SIZE 5
int nums[SIZE] = {0,1,2,3,4};
int main()
{
int i;
pid_t pid;
pid = fork();
if (pid == 0)
{
for (i = 0; i < SIZE; i++)
{
nums[i] *= -i;
printf("CHILD: %d ",nums[i]); /* LINE X */
}
}
else if (pid > 0)
{
wait(NULL);
for (i = 0; i < SIZE; i++)
printf("PARENT: %d ",nums[i]); /* LINE Y */](https://image.slidesharecdn.com/include-sys-types-h-include-stdio-h-include-unistd-h-define-230309163205-8359691c/85/include-sys-types-h-include-stdio-h-include-unistd-h-define-pdf-1-320.jpg)

The document is a C program that demonstrates process creation using the fork() system call. In the child process, it modifies an array of integers by multiplying each element by its index and prints the results. The parent process waits for the child to finish and then prints the original array values, demonstrating the difference in the output of the child and parent processes.
![#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#define SIZE 5
int nums[SIZE] = {0,1,2,3,4};
int main()
{
int i;
pid_t pid;
pid = fork();
if (pid == 0)
{
for (i = 0; i < SIZE; i++)
{
nums[i] *= -i;
printf("CHILD: %d ",nums[i]); /* LINE X */
}
}
else if (pid > 0)
{
wait(NULL);
for (i = 0; i < SIZE; i++)
printf("PARENT: %d ",nums[i]); /* LINE Y */](https://image.slidesharecdn.com/include-sys-types-h-include-stdio-h-include-unistd-h-define-230309163205-8359691c/85/include-sys-types-h-include-stdio-h-include-unistd-h-define-pdf-1-320.jpg)
