OSY_3rd_Unit_Notes
OSY_3rd_Unit_Notes
Fig. PCB
1. Process State:
The state of the process is stored in the PCB which helps to
manage the processes and schedule them. There are different states for a
process which are “running,” “waiting,” “ready,” or “terminated.”
2. Process number:
Every process is assigned a unique id known as process
ID or PID which stores the process identifier.
3. Program Counter:
While running processes when the context switch
occurs the last instruction to be executed is stored in the program counter
which helps in resuming the execution of the process from where it left
off.
4. Register:
Registers in the PCB, it is a data structure. When a process is
running and it’s time slice expires, the current value of process specific
registers would be stored in the PCB and the process would be swapped
out. When the process is scheduled to be run, the register values is read
from the PCB and written to the CPU registers. This is the main purpose
of the registers in the PCB.
5. Memory limits:
This field contains the information about memory
management system used by the operating system. This may include page
tables, segment tables, etc.
6. Accounting Information:
This information includes the amount of CPU
used, time limits, account holders, job or process number and so on. It also
includes information about listed I/O devices allocated to the process such
as list of open files.
7. List of Open files:
This information includes the list of files opened for a
process.
8. I/O Status Information:
This information includes the list of I/O devices
allocated to this process, a list of open files and so on. The PCB simply
serves as the repository for any information that may vary from process
to process.
3. Resource Tracking and Allocation: The PCB tracks all the resources
allocated to a process to make sure that the resources are used
effectively and the errors are minimized.
4. Simplified Process Control: The PCB provides a centralized structure
for storing process information, simplifying the control and
management of processes within the operating system.
1. Step – 1: The data in the register and program counter will be saved in the
PCB of process P1, let’s call it PCB1, and the state in PCB1 will be
changed.
2. Step – 2: Process P1 will be moved to the appropriate queue, which could
be ready, I/O, or waiting.
3. Step – 3: The next process, say P2, will be chosen from the ready queue.
4. Step – 4: The process P2’s state will be changed to running, and if P2 was
previously executed by the CPU, it will restart execution from where it was
put on hold.
5. Step – 5: If we need to execute process P1, we must complete all of the
tasks stated in steps 1 to 4.
Advantage of Context Switching:
2)Message Passing:
▪ In this model, communication takes place by exchanging messages
between cooperating processes.
▪ It allows processes to communicate and synchronize their action without
sharing the same address space.
▪ It is particularly useful in a distributed environment when
communication process may reside on a different computer connected by
a network.
▪ Communication requires sending and receiving messages through the
kernel.
▪ The processes that want to communicate with each other must have a
communication link between them. Between each pair of processes exactly
one communication link exists.
Need of Thread:
▪ It takes far less time to create a new thread in an existing process than to
create a new process.
▪ Threads can share the common data; they do not need to use Inter- Process
communication.
▪ Context switching is faster when working with threads.
▪ It takes less time to terminate a thread than a process.
Each line in the output shows PID, the terminal with which the process is
associated, the cumulative processor time that has been consumed since the
process has been started and the process name.
Options:
1]-a: It shows the processes of all users.
Example: ps -a
5] exit:
The exit command in Unix and Unix-like operating systems is used to
terminate a shell script or to exit a shell session. You can specify an exit status
code to indicate success or failure.
Syntax: exit
Example:
1] Basic Usage:
Example: exit
2] Using Exit Status in a Calling Script:
Example: exit 2
6] cal:
The cal command is used to display a calendar in the terminal. It can show
the current month, a specific month, or an entire year.
Syntax: cal [options] [month] [year]
Options:
• -y: Display the current year.
• -3: Display the previous, current, and next month.
• -j: Show the Julian calendar.
Example:
1] Display the Current Month:
Example: cal
2] Display a Specific Month and Year:
Example: cal 10 2024
3] Display the Current Year:
Example: cal -y
4] Display Previous, Current, and Next Month:
Example: cal -3
7] date:
The date command in Unix and Unix-like operating systems is used to display
the current date and time.
Syntax: date [OPTION]... [+FORMAT]
Options:
• -u: Display the date and time in UTC (Coordinated Universal Time).
• -d: Display a date string.
• -R: Output in RFC-2822 format.
Formatting Examples:
• %Y: Year (e.g., 2024)
• %m: Month (01-12)
• %d: Day of the month (01-31)
• %H: Hour (00-23)
Example:
1] Display the Current Date and Time:
Example: date
2] Display a Specific Date:
Example: date -d "2024-12-25"
3] Display the Current Date in UTC:
Example: date -u
Q.13] Writer the outputs of following commands
(i) Wait 2385018
(ii) Sleep 09
(iii) PS –u Asha
1. Wait command waits until the termination of specified process ID 2385018
2. Sleep command is used to delay for 9 seconds during the execution of a
process i.e. it will pause the terminal for 9 seconds.
3. ps command with -u is used to display data/processes for the specific user
Asha.