Skip to content

This guide provides essential Linux commands to manage processes, monitor system performance, and work with services.

Notifications You must be signed in to change notification settings

panwar100/Linux-Process-and-Service-Management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Linux-Process-and-Service-Management

This guide provides essential Linux commands to manage processes, monitor system performance, and work with services.

Table of Contents

  1. Process Management

  2. System Monitoring

  3. Managing Services


Process Management

View Processes

ps

Displays active processes running for the current user in the terminal.

Screenshot from 2024-11-30 22-04-26

Fields:

  • PID: Process ID.

  • TTY: Terminal associated with the process.

  • TIME: CPU time consumed by the process.

  • CMD: Command used to run the process (e.g., bash, su).

ps aux

Lists all processes in the system, including system and background tasks.

Screenshot from 2024-11-30 22-07-20

a: Shows processes of all users.

u: Includes user-related information.

x: Displays processes not attached to a terminal.

Screenshot from 2024-11-30 22-17-38

Task Status:

  • S: Sleeping.
  • I: Idle.

ps lax

provides a detailed view of the currently running processes on the system

Screenshot from 2024-11-30 22-12-02

l: This option tells ps to display the processes in "long format". The long format includes additional fields such as priority, parent process ID (PPID), and more.

a: This option shows processes of all users (not just the current user).

x: This option shows processes without a controlling terminal (background processes or daemons).

Screenshot from 2024-11-30 22-14-52

Delay Execution

sleep <seconds>

Pauses the terminal for the specified number of seconds. Example: sleep 5 pauses for 5 seconds.

Screenshot from 2024-11-30 22-20-36 Screenshot from 2024-11-30 22-20-43

Run in Background

sleep <seconds> &

When combined with the & operator, it runs in the background, allowing the terminal or script to continue with other tasks without waiting for the sleep duration to finish. Example: sleep 10000 &.

Screenshot from 2024-11-30 22-31-28

jobs: Lists active jobs in the background.

Control Foreground and Background Jobs

fg %<job_number>

Brings a background job to the foreground.

Screenshot from 2024-11-30 22-34-08

ctrl+z Suspends a foreground process.

bg %<job_number>

Resumes a suspended job in the background.

Screenshot from 2024-11-30 22-36-00

Manipulate Background Jobs

kill - %<job_number>

Sends a signal to a process to terminate or control it.

Screenshot from 2024-11-30 22-38-45

Some Signals:

-15: Terminate gracefully.

Screenshot from 2024-11-30 22-41-47

-19: Stop the process.

Screenshot from 2024-11-30 22-43-20

-18: Restart a stopped process.

Screenshot from 2024-11-30 22-44-25

-9: Forcefully kill.

Screenshot from 2024-11-30 22-45-26

-2: Interrupt (Ctrl+C equivalent).

Screenshot from 2024-11-30 22-47-08

-3: Quit.

Screenshot from 2024-11-30 22-48-15

killall -9

Forcefully terminates all processes of the specified command. Example: killall -9 sleep.

Screenshot from 2024-11-30 22-50-59

System Monitoring

System Uptime

uptime

Displays how long the system has been running, along with the load average.

Screenshot from 2024-11-30 22-59-31

Explanation of Each Component:

  • 22:54:42:

    • The current system time in 24-hour format.
  • up 1:05:

    • The system uptime, i.e., how long the system has been running since the last boot.
    • In this case, the system has been running for 1 hour and 5 minutes.
  • 2 users:

    • The number of users currently logged into the system (via terminal or remote sessions).
  • load average: 0.19, 0.39, 0.24:

    • The system's load averages over the last 1, 5, and 15 minutes.
    • Load average represents the average number of processes that are in the runnable or waiting state.

Real-Time Task Monitoring

top

Shows real-time information about running processes, including CPU and memory usage.

Screenshot from 2024-11-30 23-02-49

gnome-system-monitor

Graphical interface for monitoring processes and system performance.

Screenshot from 2024-11-30 23-04-27

Managing Services

Systemctl Commands

Systemctl is a command-line utility in Linux used to interact with and manage the systemd system and service manager. It allows you to control services, manage system states, and configure system settings

Screenshot from 2024-11-30 23-08-48

systemctl status <service>

Displays the status of the service (e.g., httpd,sshd).

Screenshot from 2024-11-30 23-33-54

Explanation of Component:

  • Loaded: Indicates that the sshd.service file is loaded, meaning the system has successfully located and read the service unit file for the SSH daemon (sshd).
  • /usr/lib/systemd/system/sshd.service: This is the path to the unit file for the sshd service, which defines how the SSH daemon should be started and managed.
  • enabled: This means that the SSH service is set to start automatically when the system boots.
  • preset: ena: Indicates that the service has been enabled by default according to the system's preset configuration.
  • Active: The service is currently running. In this case, SSH is actively serving connections.
  • active (running): This means that the SSH service is actively running without any issues.
  • since Sat 2024-11-30 21:49:43 IST: This is the timestamp of when the SSH service was started.
  • 1h 42min ago: This indicates that the SSH service has been running for 1 hour and 42 minutes since it was started.

systemctl stop/start <service>

Stops or starts the service.

Screenshot from 2024-12-01 00-02-33

Screenshot from 2024-12-01 00-03-42

systemctl enable/disable <service>

Configures the service to start automatically on boot or not.

Screenshot from 2024-12-01 00-06-11

Screenshot from 2024-12-01 00-05-11

systemctl restart <service>

Restarts the service.

systemctl reload <service>

Reloads the service configuration without restarting.

systemctl -t slice

The systemctl -t slice command in Linux is used to list all slice units managed by systemd. In systemd, a slice is a concept used to group system resources and organize services into hierarchies for better resource management and control

Screenshot from 2024-11-30 23-40-27

systemctl is-active <service>

Checks if the service is active.

Screenshot from 2024-11-30 23-45-06

systemctl is-enabled <service>

Checks if the service is enabled on boot.

Screenshot from 2024-11-30 23-44-00

systemctl list-dependencies <service>

Displays the dependencies of the service.

Screenshot from 2024-11-30 23-46-30

systemctl --failed

Lists all failed services.

Screenshot from 2024-11-30 23-29-27

systemctl mask/unmask <service>

Prevents or allows the service from being started manually or automatically

Screenshot from 2024-11-30 23-50-11

About

This guide provides essential Linux commands to manage processes, monitor system performance, and work with services.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published