Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please cany anyone send me this asap What happens when the following program exe

ID: 3786386 • Letter: P

Question

please cany anyone send me this asap

What happens when the following program executes?
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void) {
pid_t childpid;
pid_t mypid;
mypid = getpid();
childpid = fork();
if (childpid == -1) {
perror("Failed to fork");
return 1;
}
if (childpid == 0) /* child code */
printf("I am child %ld, ID = %ld ", (long)getpid(), (long)mypid);
else /* parent code */
printf("I am parent %ld, ID = %ld ", (long)getpid(), (long)mypid);
return 0;
}
Also find the value of mypid.

To compile the program after you've saved it to a file type:

cc <filename>

For example, if <filename> is assg1.c you would compile it by typing

cc assg1.c

This will create an executable file called a.out. You run the program by typing:

./a.out

Questions:

1. What happens when the code executes?

2. What is the value of mypid?

Its hsould be done in putty

hi can anyone plz send me the screen shot of the output of this code

m getting errors

i created a file assg1.c

but how to compile it by cc assg1.c

also how to findn mypid value plzz can anyone send the solution with screen shot i mean output

these are my screen shots

nclude tinelude unistd.h linclude

Explanation / Answer

1. What happens when the code executes?

I am parent 26, ID=26
I am child 27, ID=26