Process: An active entity in execution; process execution must progress in sequential fashion (active)
Program: A passive entity stored on disk (executablefile)
Program becomes process when executable file loaded into memory
Process States
New: The process is being created.
Running: Instructions are being executed.
Waiting: The process is waiting for someeventtooccur.
Ready: The process is waiting to be assignedtoaprocessor.
Terminated: The process has finishedexecution
Waiting swapped: The process was swapped while waitingfor an I/O or anevent
Process Control Block (PCB)
aka TCB
MemoryStructureofProcess(FYI no answer)
.
Ready Queue(FYI, no answer)
.
Process Scheduler:
Purpose: To maximize CPU use, quickly switch processes onto CPU for time sharing, to deliver “acceptable” response times for all programs, particularly for real time execution.
How does it work?
Process scheduler selects among available processes for next execution on CPU. The process scheduler must meet these objectives by implementing suitable policies for swapping processes in and out of the CPU.
2 Types of Schedulers
Long-term (job scheduler): selects which processes should be brought into the ready queue
invoked very infrequently (seconds, minutes) => (may be slow)
Long-term scheduler strives for good process mix
Short-term (CPU scheduler) – selects which process should be executed next and allocates CPU
invoked very frequently (milliseconds) => (must be fast)
Sometimes the only scheduler in a system
Types of Processes
I/O-bound process :
spends more time doing I/O than computations,
many short CPU bursts
CPU-bound process :
spends more time doing computations
few very long CPU bursts
Addition of Medium Term Scheduling
can be used when a system loads get high.
the scheduler will swap one or more processes out of the ready queue system for a few seconds, in order to allow smaller faster jobs to finish up quickly and clear the system
Swapping: Remove process from memory, store on disk, bring back in from disk to continue execution
Basic Commands for Process Creation in UNIX?
fork() system call creates new process
exec() system call used after a fork() to replace the processʼ memory space with a new program
wait() system call used after a fork() in the parent to sync with the created children.
exit() system call used by a process to notify the parent that has finalized.
getpid()/getppid() system call used by a process to obtain its pid and parent pid.
Abort() system call used by a parent to kill a child
Process Execution Options
Parent and children execute concurrently
fork is not blocking, the parent continues the execution
Parent waits until children terminate.
Child termination is registered with exit
Process Sharing Options
Parent and children share allresources
Children share subset of parentʼsresources
Parent and child share no resources
By default fork in Linux share all resources
Process Termination
.
Other Names related to Child Process
Zombie: when no parent, and process is terminated
Orphans: when parent is terminated but child is still running
Interprocess Communication (IPC)
a mechanism that allows processes to communicate with each other and synchronize their actions
Types:
SharedMemory
MessagePassing
Reasons for IPC
Information sharing
Computation speedup
Modularity
Type of Interprocess Communication: Shared Memory
requires one process that will be responsible of initiating/creating the area for communication in shared memory
one process creates the shared memory region
other process joins the memory region
memory region does not belong to either process, it belongs to the OS. Once done, deallocate it to prevent memory leakage.
Shared Memory System Calls
d
mmap(): maps a region of a file or device into memory
shm_open(): used to create or open a POSIX shared memory object. file is created in a virtual filesystem, and is used for shared memory
shm_unlink(): to delete a shared memory object
ftruncate(): used in conjunction with shm_open() to set the size of the shared memory object
munmap(): used to unmap a previously mapped memory region.
Interprocess Communication: Message Passing
Message system: processes communicate with each other without resorting to shared variables
IPC facility provides 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 (channel) between them
exchange messages via send/receive
Message Passing Channel Implementation
physical (e.g., shared memory, hardware bus)
logical (e.g., direct or indirect, synchronous or asynchronous, automatic or explicit buffering)
System Calls for Message Passing
mq_open() Creates a message queue
mq_send() sends a message to the message queue.
mq_receive() receives a message from the message queue.
mq_close() closes a message queue descriptor.
mq_unlink() removes a message queue from the system
Message Passing Synchronisation Type
Message passing may be either blocking or nonblocking
2 Types:
Non-Blocking: Asynchronous
Blocking: Synchronous (rendezvouz)
Message Passing: Non-Blocking
Non-blocking is considered asynchronous
Non-blocking send has the sender send the message and continue
Non-blocking receive has the receiver receive a valid message or null
Message Passing: Blocking
Blocking is considered synchronous (rendezvouz)
Blocking send has the sender blocked until the message is received
Blocking receive has the receiver blocked until a message is available
Benefit: + reliability (we know dat ahas been delivered to receiver)
Cons: - communication time is slower
Bufferring Implementation
Queue of messages attached to the link; implemented in one of three ways
Zero capacity – 0 messages Sender and receiver wait for each other (rendezvous)
Bounded capacity – finite length of n messages
A. Not Loosing Messages: Sender and receiver must wait if buffer full when sending or empty when receiving.
B. Loosing Messages: Sender and receiver don’t wait, but messages can be lost
Unbounded capacity – infinite length Sender never waits