Definition of a Process
A process in Unix is an instance of a running program. It represents the execution of a program in a specific state. It contains the program code and its current activity.
Process States (Running, Ready, Blocked)
- Running State: A process is actively executing instructions on the CPU.
- Ready State: A process is loaded into the main memory and is awaiting execution.
- Blocked State (or Waiting State): A process is temporarily inactive, often because it’s waiting for some event (e.g., I/O operation completion).
Process Control Block (PCB)
The Process Control Block (PCB) is a data structure that contains information about a process in the operating system. It includes:
- Process state
- Program counter
- CPU registers
- CPU scheduling information
- Memory management information
- I/O status information
- Accounting information
- Unique Process ID (PID)
Process ID (PID)
A Process ID (PID) is a unique numerical identifier assigned to each running process in a Unix-like operating system. It helps the system keep track of and manage individual processes.
Parent and Child Processes
- Parent Process: A process that creates another process (child process). The parent process may wait for the child process to terminate or continue its own execution.
- Child Process: A process created by another process (parent process). It inherits attributes, file descriptors, and environment variables from its parent.
Process Hierarchy
Processes are organized in a hierarchical structure, often referred to as a process tree. The root of this tree is typically the init process with PID 1. Child processes are spawned by their parent processes, creating a parent-child relationship.
Commands and Explanations
1. ps Command:
- The
pscommand is used to display information about active processes.
ps -ef- The option
-eselects all processes, and-fprovides full format listing.
2. top Command:
- The
topcommand provides a dynamic view of system processes, continuously updating in real-time.
top- It displays a list of active processes with details like PID, CPU usage, memory usage, etc.
3. pstree Command:
- The
pstreecommand displays the processes in a tree format, showing their hierarchical relationship.
pstree- This command provides a visual representation of the parent-child relationships among processes.
4. pgrep Command:
- The
pgrepcommand allows you to search for processes by their name.
pgrep <process-name>- It returns the PID(s) of processes that match the specified name.
5. pkill Command:
- The
pkillcommand is used to send signals to processes based on their name.
pkill <process-name>- This command sends a signal to all processes whose names match the specified pattern.
These commands and explanations should provide a practical understanding of the topics related to the introduction of processes.
