0% found this document useful (0 votes)
9 views8 pages

Ubuntu Process 1

A process in Ubuntu is an instance of a running program created by the Linux kernel, consisting of executable code, data, and resources. Processes can be categorized into foreground, background, daemon, and zombie processes, each with specific characteristics and management commands. Ubuntu provides various commands for process management, including 'ps' to display process information and their states.

Uploaded by

Juan Dela Cruz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

Ubuntu Process 1

A process in Ubuntu is an instance of a running program created by the Linux kernel, consisting of executable code, data, and resources. Processes can be categorized into foreground, background, daemon, and zombie processes, each with specific characteristics and management commands. Ubuntu provides various commands for process management, including 'ps' to display process information and their states.

Uploaded by

Juan Dela Cruz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

WHAT IS A PROCESS IN UBUNTU?

A process in Ubuntu (or any Linux-based system) is an instance of a running program. When you execute
a command, open an application, or run a script, the Linux kernel creates a process for that task. A process
consists of the program's executable code, data, and resources it uses (like CPU, memory, file descriptors,
and network connections).

Ubuntu, like other Linux distributions, is a multitasking and multi-user operating system, meaning that
multiple processes can run concurrently and be managed simultaneously.

TYPES OF PROCESSES

In Ubuntu, processes can be categorized into different types based on how they are created and
executed:

1. Foreground Processes
• A foreground process is one that runs directly under user control in the terminal.
• It takes input from the keyboard and sends output to the terminal.
• You can start a foreground process by typing a command and pressing Enter.
• Example:
gedit

This will open the gedit text editor as a foreground process.

• To stop a foreground process:

CTRL + Z – Stops (pauses) the process.

CTRL + C – Terminates (kills) the process.

2. Background Processes
• A background process is one that runs without user interaction.
• It does not take input from the terminal but can produce output.
• You can run a process in the background by adding & at the end of the command.
• Example:
gedit &
• To bring a background process to the foreground:

fg

• To list all background processes:


jobs
In Windows, you can run background processes in several ways, depending on your needs.
Below are different methods:

a. Using start Command in Command Prompt (CMD)


• You can run a process in the background using the start command in the
Command Prompt.
start /b notepad.exe

• The /b flag runs the process without opening a new window.


• notepad.exe starts Notepad in the background.
• If you want to run a script or batch file in the background:

start /b myscript.bat

b. Using PowerShell to Run a Process in the Background


• You can use PowerShell to start a process in the background using Start-Process.
• Example 1: Start an Application
Start-Process -NoNewWindow notepad.exe
• -NoNewWindow runs the process in the same window.
• Example 2: Run Without a Visible Window
Start-Process -WindowStyle Hidden notepad.exe
• -WindowStyle Hidden ensures the process does not appear on screen.
• Example 3: Run a Script in the Background
Start-Process -FilePath "C:\path\to\script.ps1" -WindowStyle Hidden

c. Running a Script in the Background Using Task Scheduler


• You can schedule a script to run in the background without manual execution.
• Steps:
1. Open Task Scheduler (Win + R, type taskschd.msc, press Enter).
2. Click Create Basic Task.
3. Enter a name and description, click Next.
4. Select When I log on or any other trigger.
5. Choose Start a Program and browse to your script or executable.
6. In the Advanced settings, check Run whether user is logged in or not.
7. Click Finish.
8. The script will now run in the background without a visible window.

d. Using start /min to Minimize a Window


• If you want to run a process but keep it minimized:
start /min notepad.exe

This will open Notepad in a minimized state.


e. Running a Process as a Windows Service
• If you want a long-running process to run in the background, you can create a
Windows service.
• Steps to Create a Service
1. Open PowerShell as Administrator.
2. Use the New-Service command:
New-Service -Name "MyService" -BinaryPathName "C:\path\to\myapp.exe"
3. Start the service:
Start-Service MyService
4. To stop the service:

Stop-Service MyService

• This method is useful for running background services like web servers or database
services.

f. Running Background Processes with wmic


• The Windows Management Instrumentation Command-line (WMIC) can start a
process in the background.
• Example:
wmic process call create "notepad.exe"
g. Running a Background Process with Taskkill and Tasklist
• If you need to manage background processes, use these commands:
• List running processes:
tasklist
• Kill a background process by name:
taskkill /IM notepad.exe /F
• Kill a process by PID:
taskkill /PID 1234 /F

Conclusion
There are multiple ways to run a background process in Windows:

a. CMD: start /b or start /min


b. PowerShell: Start-Process
c. Task Scheduler: Automate execution in the background.
d. Windows Services: For persistent background processes.
e. wmic: Another way to create processes in the background.
f. Task Manager: Manually start and stop processes.

Which method you choose depends on whether you want a temporary background process (like
a minimized app) or a long-running background task (like a service).
3. Daemon Processes
• A daemon is a background process that starts at system boot and runs continuously to
handle system-level tasks.
• These are service processes that don't have a terminal associated with them.
• Examples of daemons:

➢ sshd – SSH server


➢ cupsd – Printing service
➢ nginx – Web server

b. Example to check running daemons:


systemctl list-units --type=service

Windows does not use the term daemon like Linux or Unix systems, but it has an equivalent called
Windows Services. These services run in the background without user interaction and start
automatically when the system boots.

Windows Services: The Equivalent of Daemon Processes


What Are Windows Services?
• Long-running background processes that can start automatically.
• Do not require a user to be logged in.
• Managed via the Service Control Manager (SCM).
• Can be started, stopped, or restarted manually.
• Typically used for tasks like logging, networking, security monitoring, and database
management.

How to View Running Services in Windows


Method 1: Using services.msc
• Press Win + R, type services.msc, and press Enter.
• Scroll through the list to see running services.
• Right-click a service to Start, Stop, or Restart.
Method 2: Using PowerShell
• To list all services:
Get-Service
• To check the status of a specific service:
Get-Service -Name "wuauserv"
4. Zombie Processes
• A zombie process is a process that has completed execution but still has an entry in the
process table.
• It occurs when the parent process has not read the child's exit status.
• A zombie process is in the Z state.
• Example:
ps aux | grep Z
• Zombies are usually cleaned up automatically, but if not, you can manually kill the
parent process to remove them.
• Can There Be Zombie Processes in Windows?
➢ No, Windows does not have the concept of Zombie Processes because:
o Windows processes are handled differently.
o The OS immediately cleans up child processes upon termination.

PROCESS STATES

Each process in Ubuntu can be in one of the following states:

STATE CODE DESCRIPTION


R Running – The process is either running or ready to run
S Sleeping – The process is waiting for an event to complete
D Uninterruptible sleep – The process is waiting for I/O and cannot be
interrupted
T Stopped – The process is stopped (suspended)
Z Zombie – The process has terminated, but the parent has not read the exit
status
X Dead – The process is terminated and removed from the task list

PROCESS MANAGEMENT COMMANDS


Ubuntu provides several commands for managing processes:
1. ps – Display process information
• Shows a list of active processes.
• The ps command in Ubuntu (or any Linux system) is used to view running processes and
their details. It provides information like process IDs (PID), CPU usage, memory usage,
and execution status.

• Example output

• Lists processes running in the current shell session.


• Default columns: PID (Process ID), TTY (Terminal), TIME (CPU time), and CMD
(Command).

• Show All Running Processes (-e or aux)


o To see all processes running on the system:
ps -e

or

ps aux
• -e (or -A) → Shows all processes.
• aux:
o a → Shows processes of all users.
o u → Displays user information.
o x → Includes processes not attached to a terminal (like daemons).
• Example Output:

Column Breakdown
Column Meaning
USER The user who owns the process. root means the process runs with
administrator privileges.
PID Process ID (unique identifier for each running process).
%CPU Percentage of CPU time used by the process since the last update.
%MEM Percentage of physical RAM used by the process.
VSZ Virtual memory size in kilobytes (KB), including code, data, heap,
and shared libraries.
RSS Resident Set Size (actual memory in RAM), in kilobytes (KB).
TTY Terminal associated with the process (pts/1 for a user session, ? for
system processes with no terminal).
STAT Process status
START Time or date the process started.
TIME Total CPU time consumed by the process.
COMMAND The command that started the process, including arguments.

Process States in STAT Column


The STAT column shows the current state of the process. Common values:

Column Meaning
R Running (actively using CPU).
S Sleeping (waiting for an event, like user input or disk read).
D Uninterruptible sleep (usually I/O wait, cannot be killed).
Z Zombie (process finished but still in process table, waiting for
parent cleanup).
T Stopped (suspended, often from Ctrl+Z).
Z Dead (process terminated but still listed).
Modifiers:

+ → Process is in the foreground.


< → High priority process.
N → Low priority (nice process).
L → Process has pages locked in memory.

Example Analysis
a. System Process (/sbin/init)

o Owned by root
o PID = 1, the first process (init/systemd)
o Low CPU and memory usage
o TTY = ?, meaning it’s a background system process
o STAT = Ss, meaning it is a sleeping session leader
b. User Shell (bash)

• User = user1
• PID = 1234, unique process ID
• TTY = pts/1, meaning it's running in a terminal session
• STAT = Ss, meaning it's sleeping but still interactive

• Show a Specific Process by Name

ps aux | grep apache

• Filters the process list for processes containing "apache".


• Example output:

• Show a Process by PID

ps -p 1234

• Shows details for process PID 1234.

• To list only running processes:


ps -e | grep ' R '
• Show Processes in a Hierarchical Tree (f or --forest)
ps -ef –forest

• Displays parent-child relationships.


• Example

• Show CPU and Memory Usage with ps


ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem

• Lists all processes sorted by highest memory usage.

You might also like