Operating System : Operations on Process - SciComp

Post Top Ad

Responsive Ads Here

Operating System : Operations on Process

Share This

Operations on Process:

Process Creation:

During the execution, a process may create several new processes. The creating of processes is called Parent process, new processes is called children of that processes. Each of these new processes may in turn create other processes, forming a tree of processes. OS identifies the processes according to a Unique Process Identifier (PID), an integer number. The init process serves as the root parent processes for all user processes. Once the system has booted, the init process can also create various user processes, such as Web or print server, an SSH server. Children of init – Kthreadd & sshd. Kthreadd is responsible for creating additional processes that perform tasks on behalf of the kernel. SSHD responsible for managing clients that directly log onto the system. On Unix & Linux systems, we can obtain a listing processes by using PS command. The child process obtain the resources directly from the OS, or it may be constrained to a subset of the resources of parent process. When a process creates a new process, two possibilities for execution exist


1.    Parent continues to execute concurrently with its children.

2.    Parent waits until all of its children have terminated.

Two- Address Space:

1.    Child process is duplicate of the Parent process.

2.    Child process has a new program loaded into it.

A new process is created by fork() system call. It consists of a copy of the address space of the original processes. After fork() system call, one of the two processes typically uses the exec() system call to replace the process’s memory space with new program. Exec() system call loads a binary file into memory & starts its execution. Parent issue a wait() system call to move itself off the ready queue until the termination of the child.

#include <sys/types.h>

#include <stdio.h>

#include <unistd.h>

int main()

{ 

Pid_t pid;

 Pid=fork();

   if (pid<0)

         fprintf(stderr, “FORK FAILED”);

         return 1;

}

else if (pid==0)

{

 execlp(“/bin/ls”,”ls”,NULL);

}

else {

            wait(NULL);

           printf(“Child Complete”);

    }

return 0;

}

Process Terminations

A process terminates when it finishes executing its final statement. It asks the OS to delete it by using the exit() system call. All the resources of the process – includes physical & virtual memory, open files & IO buffer are deallocated.

Parent terminate the execution:

1.    Child has exceeded its usage of resources that allocated.

2.    Task assigned to the child is no longer required.

3.    Parent is exiting, the OS doesn’t allow the child to continue.

Cascading termination:

If a process terminates, then all its children must also be terminated.

Pid_t Pid;
Int status ;
Pid= wait(&status);

·        A process that has terminated, but whose parent has not yet wait(), called Zombie process.

·        If a parent didn’t invoke wait() & instead terminated, thereby leaving its child process, Orphans.

·        A parent process may wait for the termination of a child process by using wait() system call.

No comments:

Post a Comment

Post Bottom Ad

Responsive Ads Here

Pages