3.1 그림 3.30에 표시된 프로그램을 사용하여 LINE A에서 출력이 어떻게 되는지 설명하십시오.#include #include #include int value = 5;int main(){pid_t pid;pid = fork();if (pid == 0) { /* child process */value += 15;return 0;} else if (pid > 0) { /* parent process */wait(NULL);printf("PARENT: value = %d",value); /* LINE A */return 0;}}fork() is a system call used to create processes which takes no arguments and returns a process ID.When using fork() the new process which is created will become the child process of the caller and both processes will continue execution with the child process and the parent running concurrently.So there will be two instances of the program running.The child process will inherit the code, global variables, heaps and stacks, registers, and open files of its parent.However since the child is a duplicate both the parent and the child will have their own variables in this case the value variable.this means the child process will inherit the variable int value = 5 however any changes done to this v 그러나 자식 프로세스의 이 값에 대한 변경은 변수의 부모의 가치와 그 반대 방향에 영향을 미치지 않는다.따라서 부모들과 자식들을 구별하는 것은 중요하다. 왜냐하면 그들이 동일한 초기 가치를 공유할 수 있더라도 각 과정에 대해 행해진 변화는 그 과정에만 독특할 것이기 때문이다.포크()는 0의 피드를 아이와 부모 프로세스에 반환하여 자식으로부터 코드 상단에 수행한 변경 사항이 부모에 영향을 미치지 않도록 한다.그래서 변수의 값은 여전히 5이다.따라서 최종 결과는 다음과 같다: 부모:값 =53.2 초기 상위 프로세스를 포함하여 그림 3.31에 표시된 프로그램에 의해 생성되는 프로세스는 몇 개인가?#include #include int main(){/* fork a child process */fork();/* fork another child process */fork();/* and fork another */fork();return 0;}every time a fork() is executed it duplicates the already exiting processes.first fork since there is only one process after the first fork this process will be duplicated and now there will be two processes. the parent and its childsecond fork the second fork will create duplicates for each of the two processes. so now we will have two new children, since both processes have a copy. this means we will habe the two processes existing after the first fork and two new chidren meaning there are 4 processes in total.third f문이다. 이것은 우리가 첫 번째 포크 이후에 존재하는 두 가지 과정과 두 가지 새로운 과정을 모두 4개의 과정이 있다는 것을 의미한다.세 번째 포크 세 번째 포크는 네 가지 기존 프로세스를 복제할 것이다.그래서 세번째 포크후에 4명의 아이들이 더 있을것이다. 세 번째 포크가 끝나면 총 8개의 과정이 있을 것이다.세가지 포크문 뒤에 부모 과정(원본)과 자녀 7명이 있다. 총 8개의 프로세스가 있다. 이는 또한 아동 수가 2^n이 될 것이라고 명시한 N furk 연속 진술 후에 형성된 총 프로세스 수에 대한 공식에 의해 증명되었다.우리는 2^3=8명의 어린이가 될 세 개의 포크를 가지고 있기 때문에2^N 하위 프로세스.일련의 N 포크 문을 차례로 가지고 있을 경우, 구성된 총 프로세스 수는 2^N이다.5. 프로세스가 포크() 작업을 사용하여 새 프로세스를 생성하는 경우, 다음 중 상위 프로세스와 하위 프로세스 간에 공유되는 상태는?a. 스택b. 힙c. 공유 메모리 세그먼트부모 프로세스와 새로 포크된 자식 프로세스 간에 공유 메모리 세그먼트만 공유된다. 스택과 힙의 복사본은 새로 생성된 프로세스를 위해 만들어진다.3.12 초기 부모 프로세스를 포함하여 그림 3.32에 표시된 프로그램에 의해 생성되는 프로세스는 몇 개인가?#include #include int main(){int i;for (i = 0; i < 4; i++)fork();return 0;}first fork : after the first fork is executed it will create a new process. so we will have now two processes. the parent and the first child. three more forks are left.second fork : after the second fork is executed it will create two new process. Both the parent and the child created from 든 부모와 아이 둘 다 포크를 해서 우리는 두 개의 중복된 과정을 볼 수 있을 것이다. 그 결과 우리는 두 번째 포크의 끝에 네 개의 공정을 가질 것이다.세 번째 포크: 세 번째 포크가 실행된 후 두 번째 포크가 실행된 후 존재하는 네 가지 프로세스는 모두 하위 프로세스를 갖는다. 그래서 우리는 이제 8개의 프로세스를 가지게 될 것이다. 그것은 4개의 프로세스가 더 만들어졌다는 것을 의미한다.네 번째 포크: 네 번째 포크가 실행된 후, 여덟 개의 새로운 프로세스를 생성할 것이다. 이미 존재하는 8개의 과정 각각은 아이를 가질 것이다. 그것은 총 16개의 과정이 있을 것이라는 것을 의미한다. 더 이상 포크가 남아있지 않다.포크가 4개 있어서 결국엔 2^n을 가지게 될 것이고, 여기서 n=4는 최종 결과가 2^4=16이 될 것이다.3.13 그림 3.33의 인쇄물("LINE J")으로 표시된 코드 라인에 도달하는 상황을 설명한다.#include #include #include int main(){pid t pid;/* fork a child process */pid = fork();if (pid < 0) { /* error occurred */fprintf(stderr, "Fork Failed");return 1;}else if (pid == 0) { /* child process */execlp("/bin/ls","ls",NULL);printf("LINE J");}else { /* parent process *//* parent will wait for the child to complete */wait(NULL);printf("Child Complete");}return 0;}first the main process is forked. then if the child is created correctly the else statement will be executed. once the else statement is executed the code inside nd the name of the executable file. now the address space of the process is replaced with the program ls specified in the parameter. if the call to execlp succeeds of course the new program will run. However if an error occurs in the call to execlp the line printf("Line J");would be executedif an error occurs in the call to execlp the line printf("Line J"); would be executed.먼저 메인 프로세스는 fork한다. 그러면 아이가 올바르게 생성되고 다른 문장이 실행된다. 일단 다른 문장이 실행되면, 아이 내부의 코드는 execlp()로 콜 한다.앞부분에서 execlp()는 현재 프로세스 이미지를 새 프로세스 이미지로 교체하는 Exec 기능 패밀리의 일부다. exec() 명령은 현재 프로세스 공간에 로드된 실행 파일을 실행하고 진입 지점에서 실행한다. 우리의 경우 execlp()는 기능이 있는 exec()의 변형이다. 글자마다 뜻이 있다. 나는 그 기능에 목록이 전달되었다는 것을 보여준다. P는 PATH 환경 변수를 사용하여 실행할 파일 인수에서 이름이 지정된 파일을 찾는다.따라서 위의 코드 블록은 이것이 자식 프로세스라면, 새로운 프로그램을 실행하면 호출 프로세스의 프로세스 ID로 효과가 있는 새로운 프로세스 이미지로 자식 프로세스 이미지를 교체해야 한다고 말한다. execlp 내부의 인수는 계층 파일 시스템에서 새로운 프로세스 이미지의 위치와 실행 파일의 이름을 식별한다. 이제 프로세스의 주소 공간은 파라미터에 지정된 프로그램 ls로 대체된다. 만약 execlp에 대한 호출이 성공한다면, 물론 새로운 프로그램은 실행될 것이다. 그러나 실행 호출에 오류가 발생하면 line A