 Hello everyone, today we are going to learn about structure of processes in Unix operating system. The learning outcome of this video are at the end of this session student will be able to define process state model for Unix operating system and describe kernel data structures. Let us see two important kernel data structures that is process table and u area. Process table is accessible only by kernel and it contains the information about state of every active process running in the system while u area contains additional information about the process. Both process table and u area gives the context of the process that context of the process is used during context switch of the processes. So the lifetime of a process is nothing but the process from its creation to its termination. During that lifetime process undergoes among different states. So let us see what are different states of the processes. First the process is executing in user mode. Second the process is executing in kernel mode. Then the process is not executing but is ready to run for execution whenever kernel schedules it. The process is slipping and resides in main memory. The process is ready to run but swapper that is process 0 must swap the process into main memory for execution before kernel schedules it. Process is slipping and the swapper has swapped the process to secondary storage to make room for newly arriving processes in the system. The process is returning from kernel mode to user mode but the kernel prints it and does a context switch to schedule another process. The process is newly created. This is done by using fork system call. This means that process exists but it is not in ready to run state or it is not in slipping state. The process is just created and it is waiting for kernel for scheduling it for the execution. Last state is zombie state. This is the state where process uses exit system call. Here process does not exist but it leaves it static sticks so that parent process can access it. Now let us see the process state transition diagram. As we know these are total 9 states of the processes. Now let us see how process moves from these different states. Initially the process is created using fork system call that is state number 8. Now the process may enter into the state 3 or state 5 which are both ready to run but state number 3 is ready to run in memory. The process will enter here if there is enough memory available and process will enter in state number 5 if there is not enough memory present in the system. So let us consider that process enters into the state number 3. As process enters into the state number 3 the kernel schedules that process for execution and now process enters into the kernel running mode where it completes its fork system call. While executing in kernel running mode the process may enter in user running state and it executes in user mode. Now after a period of time suppose clock interrupt handler interrupts the CPU and process enters into the kernel running mode. Here in kernel running mode the kernel handles the service the clock interrupt handler and it handles the clock interrupt. So meanwhile whenever it completes its clock interrupt handling then kernel may decide to schedule another process for execution. So it will print the currently running process and that process is enter into the preempted state that is state number 7. Now the state number 7 and state number 3 are same. Both are process is in ready to run state. But only the state number 7 shows that the kernel running process is preempted by kernel the process which was executing in kernel mode. So after some time that process may be scheduled again and process enters into the user running mode and where it starts its execution in user mode. The process may make a system call while executing in user running mode. So whenever it makes a system call again it enters into the kernel running mode where it executes that system call. But suppose that system call is related with IO operation and process has to wait for IO then process will enter into the state a sleep in memory. Process will enter into the state sleep for the event IO completion. So whenever IO gets completed that process is wake up and again it is entered into the state ready to run in memory. But as there are many processes executing in the system simultaneously suppose there is not enough space in memory then that process enters into the then the processes which are sleep in memory are swept out and that process enters into the state number 6 that is sleep and swept. So after completion of an event that process can wake up and it enters into the state number 5 ready to run but swept because there is not enough space in memory. So whenever there is a space in memory that processes are swept in state number 3 again then kernel schedules that process again that process enters into the kernel running mode. Now if there is not enough space again in memory the processes are again swept out already to run process enters into the state number 5 that is ready to run and swept. So in this way again that processes are swept in state number 3 and they again enter into the kernel running mode whenever kernel schedules it then processes executes in kernel running mode. The process may enter in user running mode again they may enter in kernel running mode. So while executing in kernel running mode process may executes exit system call and it enters into the state zombie that is the last state of the process where we can say that process does not exist but that process has leave its static sticks for its parent process. So this is all about the process state transition diagram. Now let us consider that we have only one process present in the system that process enters into the running state and after some time the same process enters into the sleep state then what will happen if this sleeping process does a context switch. Just pause the video and write down your answer. Now as we know at different times kernel will call scheduler to select a new process to run but it may turn out that the scheduler finds no other task in the system. In that case scheduler will not undertake a context switch but it is simply written by doing nothing. So this shows that the context switch does not take place whenever there is only one process in the system. So if that process is in sleep state then for an IO completion event then CPU will remain idle. Now as we studied process states and transition for some states process has a control over some states transition at user level. For example process creation process can be created using fork system call. As we can see here one process executes fork system call and another process is created but after creation whether that process will enter in state number 3 or state number 5 that is decided by kernel. Process don't have control over in which state that process will enter. Similarly process can execute a system call and process may enter from user running state to kernel running state and whenever that system call is completed the process may enter into the user running but invoking a system call is process task but handling that system call is kernel task. So there may be the case that process may not enter into user running again process may execute exit system call and enters into the zombie state. So process have control over very less number of states. All states are handled by kernel in the system. Now let us see main kernel data structures that is post process table entry and U area. Process table entry is always accessible to the kernel while U area is accessible only to the running process. So the space for U area is allocated only when creating a process. It does not need U area for process table entry that do not have processes. Let us see fields present in process table entry. That field indicates that the currently running state of the process. It also contains the field for location of the process and its U area which is used by kernel whenever it does a context switch of the process. Process size gives the size of the process to identify how many number of how much space is required by that process. User identifier gives set of users who can send signals to each other. User identifier that is PID is given to the process whenever it is created using fork system call. Event descriptor is used whenever process is entered into the sleep state. Scheduling parameters gives the information about in which sequence the process entered from kernel running to user running mode. Signal field gives the how many signals are arrived to the process and how process will handle that signal. Timer field gives the accounting information and the overall time required for execution of the process. Now let us see the fields present in U area. First is pointer. It points to the process table entry. Then real and effective user ID gives the access rights of the processes. Timer field gives the how much time that process has spent in user mode and kernel mode. This way indicates how process will react to the signals sent to the process. Control terminal field gives information about the login terminal of the process if exist. Error field gives the error written by system call. Return value field gives the result of the system call whenever it is written from that system call. Studio parameters gives the information about the source and target addresses and amount of data to be transferred. Current directory and current directory and current root gives information about file system environment while user file descriptor table gives information about the files open by these processes. Limit fields gives the limits on the process, size of the process and size of the file created by that process or the size of a file it can write. The permission mode field mask the mode setting on the files that the process creates. Suppose process create a file then the permission mode will set whether that file has read mode, write mode, execute mode. These are the different modes set by the process. So this is all about process state transitions and two kernel data structures that is process table entry and u area. So this is the references.