Question

In: Computer Science

Explain what the difference is between a process and a program. Explain what would happen if...

  1. Explain what the difference is between a process and a program.
  1. Explain what would happen if a parent process exits immediately after calling the fork() system call.

Solutions

Expert Solution

Difference between a process and a program.

PROCESS: If a Program in Execution, then it is called Process. It is also the amount of work done to run a program.

PROGRAM: A sequence of instructions written in any Programming Language using an extension. It is also the subpart of process.

PROCESS

PROGRAM

Consists of Instructions are in Machine code at the time of Execution.

Instructions are in any programming languages like c++, Java etc.

Reside in Main Memory

Reside in Secondary Storage Devices.

Process is a Dynamic Object

Program is Static Object

Span of time is Limited

Span of time is unlimited

Entity is active and perform the intended functions of its related program

Entity is passive such as the contents of a file stored on a Disk

Basic process management is done with many system calls. System calls can be combined to solve a complex task. Fork () System call is used to create a duplicate process or new process is known as child process. The main process or calling process is known as Parent process. When the child process is created by using fork system call, both parent and children will have same relative address and different absolute address. Using the Process ID (pid) we can identify parent and child. After the fork () system call, the return value of parent pid is the child pid and the child pid is zero.

Exit () is a system call for the termination of process after it finishes the execution. There is no return value for exit () System call. Wait () is another system call that blocks the execution of parent process until one of its child process terminates. After child exits, parent process will resume its action.

Process whose parent process has terminated after calling the fork () system call, is called orphan process. The child remains running itself. The orphaned process will give to a special init system process or root process with PID 1 in the case of UNIX operating systems. Kernel, the main component in the OS for inter-process communication automatically sets the parent as init. This is known as re-parenting. After that, root process waits for the termination of orphan process. In the case of other operating systems, kernel suddenly terminates the orphan process. When this concept coming into modern Linux systems, init is replaced by sub reaper. Orphaned process will be given to the nearest still living ancestor subreaper.

Given below is the simple C language code for the Explanation of fork () System call.

int main()

{    

// fork () Create a child process

      int pid = fork();           

     if (pid > 0)

{

//getpid() returns process id                    

// while getppid() will return parent process id                 

printf("Parent process\n");                       

printf("ID : %d\n\n",getpid());

}             

else if (pid == 0)

                {             

printf("Child process\n");                         

// getpid() will return process id of child process                              

printf("ID: %d\n",getpid());

// getppid() will return parent process id of child process                             

printf("Parent -ID %d\n\n",getppid());                 

sleep(10);                           

// At this time parent process has finished.                         

// So if u will check parent process id     

// it will show different process id                           

printf("\nChild process \n");                      

printf("ID: %d\n",getpid());                        

printf("Parent -ID: %d\n",getppid());

                }

                else

                {

                printf("Failed to create child process");

                }                             

return 0;

}

Output:

Child Process ID: 12591

Parent – ID 1


Related Solutions

Explain the difference between nominal and real interest rates. Explain the process you would need to...
Explain the difference between nominal and real interest rates. Explain the process you would need to follow to determine the nominal interest rate and the real interest rate if you were considering buying a five-year bond with quoted annual interest rate of 4.5%
1. Explain the process of creating a significance test. 2. What is the difference between a...
1. Explain the process of creating a significance test. 2. What is the difference between a z-distribution and a t-distribution? When would you use each of them. 3. How do confidence intervals and significance tests relate? 4. What does having the value of zero contained in a confidence interval for a difference tell you? 5. When do you use a matched-pairs t-test?
Explain the difference between process capability and statistical control. Suppose that a process with a normally...
Explain the difference between process capability and statistical control. Suppose that a process with a normally distributed output has a mean of 50.0 cm. and a variance of 3.61 cm. If the specifications are 51.0 +/- 3.75 cm., a. Compute Cp and Cpk b. What are your conclusions about this process?
what is the difference between business process reengineering and business process management
what is the difference between business process reengineering and business process management
1. What would happen if there was a hole between the right side of the heart...
1. What would happen if there was a hole between the right side of the heart and the left side? What would this be called? 2. What causes blood to flow from one chamber or vessel to another? 3. What happens to the pressure inside a chamber when the myocardium contracts?
what is the difference between job costing and process costing?
what is the difference between job costing and process costing?
What is the difference between a zero-wait and a uis process?
What is the difference between a zero-wait and a uis process?
What is the difference between primary markets and secondary markets?Explain What is the difference between money...
What is the difference between primary markets and secondary markets?Explain What is the difference between money markets and capital markets?Explain What are three (3) of the seven (7) types of financial institutions? Include a description of the main services offered by each. Explain Why would the U.S. government, local governments, and corporations issue bonds? Explain Provide the definitions of a discount bond and a premium bond. Give examples. As owners, what rights and advantages do shareholders obtain? Explain Why might...
Explain the similarity and difference between process costing and job-order costing.
Explain the similarity and difference between process costing and job-order costing.
What would happen if we cannot process an amino acid that is needed by our body?...
What would happen if we cannot process an amino acid that is needed by our body? Can you describe a disease associated with defects in the amino acid biosynthetic pathway?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT