[OS] Process 2
Updated:
Process Part 2
Operations in Processes
- Process creation
- Process termination
- Inter-process communication
- etc…
Process Creation
- A process (parent) can create another processes (children)
- Siblings are children with the same parent process
- Form a tree of processes
- Generally, process identified and managed via a process identiier (PID)
- Resource sharing options
- Parent and children share all resources
- Children share subset of parent’s resources
- Parent and child share no resources
- Execution options
- Parent and children execute concurrently
- Parent waits until children terminate
- fork()
- Create a new process by cloning the current process (allocate memory)
- Child duplicates the parent’s address space (but have different PCB)
- exec()
- System call used ater a fork() to replace the process’ memory space with a new program
- New process overwrite existed process (no more “existed process” exist)
- CPU scheduler decides which one to execute first between parent and child
Process Termination
- Process executes last statement and then asks the operating system to delete it using the exit() system call
- Returns status data from child to parent via wait()
- Parent process wait until child process dead
- Process’ resources are deallocated by operating system
- Parent may terminate the execution of children processes using the abort() system call
- When child has exceeded allocated resources
- When the task assigned to child is no longer required
- When the parent is exiting and the operating system does not allow a child to continue if its parent terminates (cascading termination)
- Parent process may wait for termination of a child process by using the wait() system call
- The call returns status information and the pid o the terminated process
- pid = wait(&status)
- A process which is terminated but parents its parent has not called wait() yet becomes zombie
- If parent terminated without calling wait(), process is orphan (child is still alive)
- Zombie and orphan process cause memory waste problem
Multiprocess Architecture (Chrome Browser)
- Many web browsers ran as single process
- If one web site casues trouble, entire browser can be crashed
- Google Chrome Browser is multiprocess with 3 different types of processes
- Browser, Renderer, Plug-in
- But, waste memory resource problem
Interprocess Communication
- Processe within a system may be independent or cooperating
- Independent processes cannot affect or be affected by the execution of another process
- Cooperating process can affect or be affected by other processes, including the procedure of sharing data
- Information sharing
- Computation speedup
- Modularity
- Convenience
- Cooperating processes need Inter-process communication(IPC)
- Shared memory
- Message passing
Communication Models
Producer-Consumer problem
- Producer process produces information that is consumed by a consumer process
- Make sure that the producer does not overflow the buffer
- Make sure that the consumer does not pull from an empty bufer
Interprocess Communication - Shared Memory
- An area of memory shared among the processes that wish to communicate (use buffer)
- Pros
- The communication is under the control of the users processes not the operating system
- OS overhead not happen
- Cons
- Synchronization problem when lots of processes access the shared memory
Interprocess Communication - Message Passing
- OS controls the mechanism for processes to communicate and to synchronize their actions
- Message system : processes communicate with each other without resorting to shared variables
- Two operations
- send(message)
- receive(message)
- If processes P and Q wish to communicate, then
- Establish a communication link between them
- Exchange messages via send/receive
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 communiation link
- Links are established automatically
- A link is associated with exactly one pair of communicating processes
- Between each pair, there exist exactly one pair
- The link may be undirectional, but is usually bi-directional
- Symmetric links
- Both the sender and receiver specify the other partner
- Asymmetric links
- Only the sender specifies the receiver
Indirect Communication
- Messages are directed and received from mailboxes
- Each mailbox has a unique id(POSIX message queues)
- Processes can communicate only if they share a mailbox
- send(A,message) : send a message to mailbox A
- receive(A,message) : receive a message from mailbox A
- Properties of communication link
- Link established only if processes share a common mailbox
- A link may be assoicated with many processes
- Each pair of processes may share several communication links
- Link may be unidirectional or bi-directional
Synchronization
- Message passing may be either blocking or non-bloking
- Blocking (synchronous)
- Blocking send : the sender is blocked until the message is received
- Blocking receive : the receiver is blocked until a message is available
- Non-Blocking (asynchronous)
- Non-Blocking send : the sender sends the message and continue
- Non-Bloking receive : the receiver receives a valid message or null
Communication in Client-Server systems
- Shared memory
- Message passing (Pipes)
- Sockets
- Remote Procedure Calls (RPC)
Pipes
- Ordinary pipes
- cannot be accessed from outside the process that created it
- Typically, a parent process creates a pipe and uses it to communiate with a child process that it created
- allow communication in 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)
- Unidirectional
- Require parent-child relationship between communicating processes
- Named pipes
- can be accessed without a parent-child relationship
- more powerful than ordinary pipes
- Bidirectional
- No parent-child relationship is necessary
- Several processes can use the named pipe for communication
- stay alive even after process terminates
Sockets
- A socket is defined as an endpoint for communication
- Concatenation of IP address and port
- The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8
- Communication consists between a pair of sockets
- All ports below 1024 are well known, used for standard services
- Specia IP address 127.0.0.1 to refer to system on which process is running
- Three types of sockets
- Connection-oriented (TCP)
- Connectionless (UDP)
- MulticastSocket class
Remote Procedure Calls (RPC)
- abstracts procedure calls between processes on networked systems
- Stubs : client-side proxy that abstracts the actual procedure
- The client-side stub locates the server and packaging parameters into a form for transmission on network
- The server-side stub receives this message, unpacks parameters and performs the procedure on the server
Leave a comment