2. Process Introduction
Process States
Process Control Block (PCB or TCB)
Process creation and I/O Requests
Schedulers
3. A program in execution
Process in memory has
◦ Text section (includes program code)
◦ Data section (global variables)
◦ Stack (contains the return address, local address,
function parameters)
◦ Heap (dynamic runtime memory during the
execution of process and this may vary)
6. Program is a passive entity
Program stores sequence of instructions written
in a file stored in the secondary memory
Process is active entity which has program
counter that tells the next instruction to be
executed and also has a set of associated
resources.
Program becomes a process when the file is
loaded in the primary memory
◦ Example: double click the executable file of running
a.out is example of program -> process
7.
8. New – a process is generated
Ready – multiple processes are ready to run
under a CPU.
Running – currently executing on the CPU
Waiting – Waiting for an Event or an IO, Once
the event is available, process moves to the
ready state.
Terminated – Process is killed or terminated
9.
10. Identifier: A unique identifier associated with this
process, to distinguish it from all other
processes.
State: If the process is currently executing, it is in
the running state.
Priority: Priority level relative to other processes.
Program counter: The address of the next
instruction in the program to be executed.
Memory pointers: Includes pointers to the
program code and data associated with this
process, plus any memory blocks shared with
other processes.
11. Context data: These are data that are present
in registers in the processor while the process
is executing.
I/O status information: Includes outstanding
I/O requests, I/O devices (e.g., disk drives)
assigned to this process, a list of files in use
by the process, and so on.
Accounting information: May include the
amount of processor time and clock time
used, time limits, account numbers, and so
on.
12. pid_t pid Process identifier
Long state State of a process
Unsigned int time_slice Scheduling information
Struct task_struct *parent This process’s parent
Struct list_head child; This process’s children
Struct files_struct *files List of open files
Struct mm_struct *mm Addresss space of this process
13.
14.
15.
16. int main()
{
pid_t pid;
pid =fork();
if (pid < 0) { I* error occurred *I
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0) { I* child process *I
execlp("lbinlls","ls",NULL);
}
else { I* parent process *I
}
wait (NULL) ;
printf("Child Complete");
return 0;}
17. A process migrates among various scheduling
queues throughout its lifetime
Long Term Scheduler or Job Scheduler
◦ in a batch system, more processes are submitted
than can be executed immediately.
◦ execute less frequently
Short Term Scheduler or CPU Scheduler
◦ selects from among the processes that are ready
to execute and allocates the CPU to one of them.
◦ Runs most frequently (ex: runs every 100ms)
18. Processes are either I/O Bound or CPU Bound
Long Term schedulers should have the
correct mix of I/O Process and CPU Bound
processes
Short Term Scheduler schedules the
Processes that are ready to run under the CPU
So Unix and Microsoft does not have Long
Term Schedulers as it more time to get
executed
19. When an interrupt occurs, the state of the
process to be saved which called as context
switching
It depends highly on the hardware support
Hardware architecture should have more
number of registers as compared to more
number of context switches.
20. Reasons for IPC
◦ Information Sharing
Sharing file between processes
◦ Computational Speedup
Processes are break down in to sub-process
◦ Modularity
◦ Convenience
Individual user can work on many tasks at the same
time
21. Independent Processes
◦ No interference with other processes in the system
Cooperative processes
◦ Shared Memory
◦ Message Passing
22.
23. Message Passing
◦ Suitable for smaller amount of data
◦ Easier to implement
◦ Usually implemented using System calls, so kernel
is bothered every-time during message
communication
Shared Memory
◦ Faster to implement
◦ system calls are required only to establish shared-
memory regions.
◦ Once shared memory is established, all accesses are
treated as routine memory accesses, and no
assistance from the kernel is required.
24. Use of Producer – Consumer relations
Producer will produce and consumer will
consume the items produced by the producer
P-C problem achieved through
◦ Unbounded buffer
No limit on the size of queue
The consumer may have to wait for new items
but the producer can always produce new items.
◦ Bounded buffer
Implement like a circular Queue
Producer will wait if the queue is full
Consume will waif if the queue is empty
25. #define BUFFER_SIZE 10
typedef struct {
…
}item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
/*
Buffer is empty when in==out
Buffer is full when ((in+1)%BUFFER_SIZE)==out
*/
26. while (true) {
/* produce an item in nextProduced *I
while ( ((in + 1) % BUFFER_SIZE) == out)
I* do nothing *I
buffer[in] = nextProduced;
in = (in + 1) % BUFFER_SIZE;
}
27. item nextConsumed;
while (true) {
while (in == out)
; II do nothing
nextConsumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
I* consume the item in nextConsumed *I
}