Concept of Process

3:48 AM Posted In Edit This 1 Comment »
1. Concept of process Process Concept An operating system executes a variety of programs: Batch system – jobs Time-shared systems – user programs or tasks Process – a program in execution; process execution must progress in sequential fashion Note: process (active entity) is different from program (passive entity). Several processes may be instances of the same program. A process includes, e.g.: program counter Stack
data section
a. Process State During the lifespan of a process, its execution status may be in one of four states: (associated with each state is usually a queue on which the process resides) Executing: the process is currently running and has control of a CPU Waiting: the process is currently able to run, but must wait until a CPU becomes available Blocked: the process is currently waiting on I/O, either for input to arrive or output to be sent Suspended: the process is currently able to run, but for some reason the OS has not placed the process on the ready queue Ready: the process is in memory, will execute given CPU time. b.Control block If the OS supports multiprogramming, then it needs to keep track of all the processes. For each process, its process control block PCB is used to track the process's execution status, including the following: Its current processor register contents Its processor state (if it is blocked or ready) Its memory state A pointer to its stack Which resources have been allocated to it Which resources it needs c.Threads Despite of the fact that a thread must execute in process, the process and its associated threads are different concept. Processes are used to group resources together and threads are the entities scheduled for execution on the CPU.A thread is a single sequence stream within in a process. Because threads have some of the properties of processes, they are sometimes called lightweight processes. In a process, threads allow multiple executions of streams. In many respect, threads are popular way to improve application through parallelism. The CPU switches rapidly back and forth among the threads giving illusion that the threads are running in parallel. Like a traditional process i.e., process with one thread, a thread can be in any of several states (Running, Blocked, Ready or Terminated). Each thread has its own stack. Since thread will generally call different procedures and thus a different execution history. This is why thread needs its own stack. An operating system that has thread facility, the basic unit of CPU utilization is a thread. A thread has or consists of a program counter (PC), a register set, and a stack space. Threads are not independent of one other like processes as a result threads shares with other threads their code section, data section, OS resources also known as task, such as open files and signals. Processes Vs Threads As we mentioned earlier that in many respect threads operate in the same way as that of processes. Some of the similarities and differences are: Similarities Like processes threads share CPU and only one thread active (running) at a time. Like processes, threads within a processes, threads within a processes execute sequentially. Like processes, thread can create children. And like process, if one thread is blocked, another thread can run. Differences Unlike processes, threads are not independent of one another. Unlike processes, all threads can access every address in the task . Unlike processes, thread are design to assist one other. Note that processes might or might not assist one another because processes may originate from different users.


In multiprogramming OS, multiple jobs are held in memory and alternate between using the CPU, using I/O, and waiting (idle) The key to high efficiency with multiprogramming is effective scheduling – High-level – Short-term – I/O High-level scheduling – Determines which jobs are admitted into the system for processing – Controls the degree of multiprocessing – Admitted jobs are added to the queue of pending jobs that is managed by the short-termscheduler – Works in batch or interactive modes Short-term scheduling – This OS segment runs frequently and determines which pending job will receive the CPU’s attention next – Based on the normal changes of state that a job/process goes through – A process is running in the CPU until: +It issues a service call to the OS (e.g., for I/O service) + Process is suspended until the request is satisfied. Process causes and interrupt and is Suspended. External event causes interrupt – Short-term scheduler is invoked to determine which process is serviced next.


∗ cpu executes a process

∗ Kernel suspends process when its time quantum elapses

∗ Kernel schedules another process to execute

∗ Kernel later reschedules the suspended processAllocates main memory for an executing process


2. Process Scheduling
a. Scheduling Queues

Job queue – set of all processes in the system Ready queue – set of all processes residing in main memory, ready and waiting to execute Device queues – set of processes waiting for an I/O device Processes migrate among the various queues


b.Schedulers
is a kernel scheduling design that can schedule processes within a constant amount of time, regardless of how many processes are running on the operating system (OS). One of the major goals of operating system designers is to minimize overhead and jitter of OS services, so that application programmers who use them endure less of a performance impact. An O(1) scheduler provides "constant time" scheduling services, thus reducing the amount of jitter normally incurred by the invocation of the scheduler. In the realm of real-time operating systems, deterministic execution is key, and an O(1) scheduler is able to provide scheduling services with a fixed upper-bound on execution times.

c.context switch
context switch is the computing process of storing and restoring the state (context) of a CPU such that multiple processes can share a single CPU resource. The context switch is an essential feature of a multitasking operating system. Context switches are usually computationally intensive and much of the design of operating systems is to optimize the use of context switches. A context switch can mean a register context switch, a task context switch, a thread context switch, or a process context switch. What constitutes the context is determined by the processor and the operating system.
In a context switch, the state of the first process must be saved somehow, so that, when the scheduler gets back to the execution of the first process, it can restore this state and continue. The state of the process includes all the registers that the process may be using, especially the program counter, plus any other operating system specific data that may be necessary. Often, all the data that is necessary for state is stored in one data structure, called a switchframe or a process control block. Now, in order to switch processes, the switchframe for the first process must be created and saved. The switchframes are sometimes stored upon a per-process stack in kernel memory (as opposed to the user-mode stack), or there may be some specific operating system defined data structure for this information. Since the operating system has effectively suspended the execution of the first process, it can now load the switchframe and context of the second process. In doing so, the program counter from the switchframe is loaded, and thus execution can continue in the new process. New processes are chosen from a queue or queues. Process and thread priority can influence which process continues execution, with processes of the highest priority checked first for ready threads to execute.





3.Process Operation
a.Process Creation
In general-purpose systems, some way is needed to create processes as needed during operation. There are four principal events led to processes creation. System initialization. Execution of a process Creation System calls by a running process. A user request to create a new process. Initialization of a batch job. Foreground processes interact with users. Background processes that stay in background sleeping but suddenly springing to life to handle activity such as email, webpage, printing, and so on. Background processes are called daemons. This call creates an exact clone of the calling process.A process may create a new process by some create process such as 'fork'. It choose to does so, creating process is called parent process and the created one is called the child processes. Only one parent is needed to create a child process. Note that unlike plants and animals that use sexual representation, a process has only one parent. This creation of process (processes) yields a hierarchical structure of processes like one in the figure. Notice that each child has only one parent but each parent may have many children. After the fork, the two processes, the parent and the child, have the same memory image, the same environment strings and the same open files. After a process is created, both the parent and child have their own distinct address space. If either process changes a word in its address space, the change is not visible to the other process.

b.Process Termination
A process terminates when it finishes executing its last statement. Its resources are returned to the system, it is purged from any system lists or tables, and its process control block (PCB) is erased i.e., the PCB's memory space is returned to a free memory pool. The new process terminates the existing process, usually due to following reasons: Normal Exist Most processes terminates because they have done their job. This call is exist in UNIX. Error Exist When process discovers a fatal error. For example, a user tries to compile a program that does not exist. Fatal Error An error caused by process due to a bug in program for example, executing an illegal instruction, referring non-existing memory or dividing by zero. Killed by another Process A process executes a system call telling the Operating Systems to terminate some other process. In UNIX, this call is kill. In some systems when a process kills all processes it created are killed


4.Cooperating Processes

Cooperating process can affect or be affected by the execution of another process • Advantages of process cooperation – Information sharing – Computation speed-up – Modularity – Convenience Advantages of process cooperation Information sharing Computation speed-up Modularity Convenience Independent process cannot affect/be affected by the execution of another process, cooperating ones can Issues Communication Avoid processes getting into each other’s way Ensure proper sequencing when there are dependencies Common paradigm: producer-consumer unbounded-buffer - no practical limit on the size of the buffer bounded-buffer - assumes fixed buffer size


5.Interprocess communication
For communication and synchronization Shared memory OS provided IPC Message system no need for shared variable two operations send(message) – message size fixed or variable receive(message) If P and Q wish to communicate, they need to establish a communication link between them exchange messages via send/receive Implementation of communication link physical (e.g., shared memory, hardware bus) logical (e.g., logical properties)