Process in os

Process in os

Process Notes: 

What is the process?

Process: A process is defined as an entry which represents the basic unit which represents the basic unit of work to be implemented in the system. So we can say, program execution time is a process.



What are Process State and its diagram?
Ans: As a process executes, it changes state. The state of a process is defined in part by the current activity of that process. A process may be in one of the following states:

  • New: The process is being created.
  • Running: Instructions are being executed.
  • Waiting: The process is waiting for some event to occur (such as an I/O completion or reception of a signal).
  • Ready: The process is waiting to be assigned to a processor.
  • Terminated: The process has finished execution.



Process Control Block (PCB)
Information associated with each process (also called task control block)
  • Process state – running, waiting, etc
  • Program counter – location of instruction to next execute
  • CPU registers – contents of all process-centric registers
  • CPU scheduling information- priorities, scheduling queue pointers
  • Memory-management information – memory allocated to the process
  • Accounting information – CPU used, clock time elapsed since the start, time limits
  • I/O status information – I/O devices allocated to a process, list of open files


Process Scheduling explain with queue?
ans: There are three Process Scheduling queues, they are-
  • Maintains scheduling queues of processes
    • 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 – a set of processes waiting for an I/O device
 There are three Process schedulers, they are-
  • Short-term scheduler  (or CPU scheduler) – selects which process should be executed next and allocates CPU
    • Sometimes the only scheduler in a system
    • Short-term scheduler is invoked frequently (milliseconds) ⇒ (must be fast)
  • Long-term scheduler  (or job scheduler) – selects which processes should be brought into the ready queue
    • Long-term scheduler is invoked  infrequently (seconds, minutes) ⇒ (may be slow)
    • The long-term scheduler controls the degree of multiprogramming
  • Medium-term scheduler  can be added if degree of multiple programming needs to decrease
    • Remove process from memory, store on disk, bring back in from disk to continue execution: swapping



what type of process?
Ans: There are 4 types
  • I/O bounded
  • CPU bounded
  • Independent
  • Co-Operative

Proper mix control
Ans: Job Scheduler doing that proper mix process. it gives ready queue 50% boundary, CPU queue 50%, and others percent for device queue. Proper mixing control degree of multiprogramming.



Process Creation

Note: Process create by fork() function
  • Parent processes create children processes, which, in turn, create other processes, forming a tree of processes
  • Generally, the process is identified and managed via a process identifier (pid)
  • Resource sharing options
    • Parents and children share all resources
    • Children share a subset of parent’s resources
    • Parent and child share no resources
  • Execution options
    • Parents and children execute concurrently
    • Parent waits until children terminate
    • The child may execute parallel with parents.
Cascading termination


  • Parents normally terminate then all children terminate
1. Zombie process child
    • This child's parents do not wait
2. Orphan process child
    • This child's parent did not terminate but the child already terminate.
Process Termination
  • A parent may terminate the execution of children's processes using the abort() system call.  Some reasons for doing so:
    • The child has exceeded the allocated resources
    • Task assigned to a child is no longer required
    • The parent is exiting and the operating system does not allow  a child to continue if its parent terminates
Ques: what are the reasons for process termination?
Ans: Process termination reason is that:
1. A process may be terminated after its execution is naturally completed.
2. A child's process may be terminated if its parents' process request for its termination.
3. A process can be terminated if it tries to use a resource that it is not allowed to.
4. If an I/O failure occurs for a process, it can be terminated.
5. If a parent's process is terminated then its child's process is also terminated.

Interprocess Communication
Advantages of process cooperation
• Information sharing. Since several users may be interested in the same piece of information (for instance, a shared file), we must provide an environment to allow concurrent access to such information.
• Computation speedup. If we want a particular task to run faster, we must break it into subtasks, each of which will be executed in parallel with the others. Notice that such a speedup can be achieved only if the computer has multiple processing cores.
• Modularity. We may want to construct the system in a modular fashion, dividing the system functions into separate processes or threads.
• Convenience. Even an individual user may work on many tasks at the same time. For instance, a user may be editing, listening to music, and compiling in parallel.
 
  • Two models of IPC
    • Shared memory
    • Message Passing
Shared memory
  • An area of memory shared among the processes that wish to communicate
  • The communication is under the control of the users' processes, not the operating system.
  • The major issue is to provide a mechanism that will allow the user processes to synchronize their actions when they access shared memory.
 In the shared-memory model,
  • A region of memory that is shared by cooperating processes is established.
  • Any process established shared memory then add an address to other cooperating process.
  • They exchange information using write and read operation
  • Once shared memory is established, they can communicate without the interaction of os.



Message-Passing Systems
Communication takes place by means of messages exchanged between the cooperating process

  • The mechanism for processes to communicate and synchronize their actions
  • Message system – processes communicate with each other without resorting to shared variables
  • IPC facility provides two operations:
    • send(message)
    • receive(message)
  • The message size is either fixed or variable
Message Passing (Cont.)
  • If processes P and Q wish to communicate, they need to:
    • Establish a communication link between them
    • Exchange messages via send/receive
  • Implementation issues:
    • How are links established?
    • Can a link be associated with more than two processes?
    • How many links can there be between every pair of communicating processes?
    • What is the capacity of a link?
    • Is the size of a message that the link can accommodate fixed or variable?
    • Is a link unidirectional or bi-directional?
  • Implementation of a communication link
    • Physical:
      • Shared memory
      • Hardware bus
      • Network
    • Logical:
      •  Direct or indirect
      •  Synchronous or asynchronous
      •  Automatic or explicit buffering

 
Message-Passing Systems types
  • Direct communication
  • indirect communication
  • Synchronous communication
  • Asynchronous communication
Direct Communication

  • Processes must name each other explicitly:
    • send (P, message) – send a message to process P
    • receive(Q, message) – receive a message from process Q
  • Properties of a communication link
    • Links are established automatically
    • A link is associated with exactly one pair of communicating processes
    • Between each pair, there exists exactly one link
    • The link may be unidirectional, but is usually bi-directional
Indirect Communication

  • Messages are directed and received from mailboxes (also referred to as ports)
    • Each mailbox has a unique id
    • Processes can communicate only if they share a mailbox
  • Properties of the communication link
    • Link established only if processes share a common mailbox
    • A link may be associated with many processes
    • Each pair of processes may share several communication links
    • The link may be unidirectional or bi-directional
  • Operations
    • create a new mailbox (port)
    • send and receive messages through the mailbox
    • destroy a mailbox
  • Primitives are defined as:
                send(A, message) – send a message to mailbox A
                receive(A, message) – receive a message from mailbox A
  • Mailbox sharing
    • P1, P2, and P3 share mailbox A
    • P1, sends; P2 and P3 receive
    • Who gets the message?
  • Solutions
    • Allow a link to be associated with at most two processes
    • Allow only one process at a time to execute a receive operation
    • Allow the system to select arbitrarily the receiver.  Sender is notified of who the receiver was.
Pipes
  • Acts as a conduit allowing two processes to communicate
  • Issues:
    • Is communication unidirectional or bidirectional?
    • In the case of two-way communication, is it half or full-duplex?
    • Must there exist a relationship (i.e., parent-child) between the communicating processes?
    • Can the pipes be used over a network?
  • Ordinary pipes – cannot be accessed from outside the process that created them. Typically, a parent process creates a pipe and uses it to communicate with a child process that it created.
  • Named pipes – can be accessed without a parent-child relationship.
Ordinary Pipes
  • Ordinary Pipes allow communication in a standard producer-consumer style
  • Producer writes to one end (the write-end of the pipe)
  • Consumer reads from the other end (the read-end of the pipe)
  • Ordinary pipes are therefore unidirectional
  • Require parent-child relationship between communicating processes
  • Windows call these anonymous pipes
  • See Unix and Windows code samples in the textbook
Named Pipes
  • Named Pipes are more powerful than ordinary pipes
  • Communication is bidirectional
  • No parent-child relationship is necessary between the communication processes
  • Several processes can use the named pipe for communication
  • Provided on both UNIX and Windows systems
Context Switch
  • When the CPU switches to another process, the system must save the state of the old process and load the saved state for the new process via a context switch
  • Context of a process represented in the PCB
  • Context-switch time is overhead; the system does no useful work while switching
    • The more complex the OS and the PCB the longer the context switch
  • Time-dependent on hardware support
    • Some hardware provides multiple sets of registers per CPU and multiple contexts loaded at once