How to see process linux

Find out what processes are running in the background on Linux

How to find out what processes are running in the background

  1. You can use the ps command to list all background process in Linux. Other Linux commands to obtain what processes are running in the background on Linux.
  2. top command – Display your Linux server’s resource usage and see the processes that are eating up most system resources such as memory, CPU, disk and more.
  3. htop command – Just like a top command but with an improved user interface.

Let us see both traditional command and modern commands examples that one can use to manage running processes in Linux.

How can I run a Linux process in the background?

To run your process or command/shell script in the background, include an & (an ampersand) at the end of the command/shell script you use to run the job. For example:
command &
/path/to/script &
sleep 10000 &

List your background processes

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

To stop the foreground process press CTRL + z . One can refers to the background process or stopped process by number. For example, vim is stopped and has 1 as number, so run the bg command to restart a stopped background process:
bg %n
bg %1
One can bring a background process to the foreground such as sleep command using the fg command:
fg %n
fg %2
Finally, kill a running process named “sleep 10000” using the kill command:
kill %n
kill %2

Linux background processes list command

Open the terminal application and issue the following ps command command to show all running process on the system including those running in the background:
$ sudo ps -aux | less
OR
# ps aux | more

List all running processes on Linux using ps command

Understanding ps command outputs

The first column shows the user name who started the foreground or background processes on Linux system. For example, the daemon user started the atd process. The process name itself displayed in the last column. The STAT coloum gives us the state of a Linux process:

Process STATE code Description
D uninterruptible sleep (usually IO)
I Idle kernel thread
R running or runnable (on run queue)
S interruptible sleep (waiting for an event to complete)
T stopped by job control signal
t stopped by debugger during the tracing
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z defunct (“zombie”) process, terminated but not reaped by its parent

Typically process in “interruptible sleep” are running in the background and shows a “ S ” on processes STAT column. The interruptible sleep means the process can be terminated or killed with the help of kill command. On the other hand, processes in a “D” or uninterruptible sleep state are usually waiting on I/O. Therefore, you cannot kill “D” state processes as they are uninterruptible. Additional characters may be displayed as follows too:

Читайте также:  Диспетчер загрузки windows биос
Process STATE code Description
high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ is in the foreground process group

Is my Linux process running in the foreground or background?

Based upon the above tables, one can determine if Linux process in background or foreground or running and so on.

Command/
Process
ps STATE code Foreground or Background?
/sbin/init Ss Background process (interruptible sleep and a session leader)
/usr/sbin/rsyslogd -n Ssl Background process (interruptible sleep+a session leader and multi-threaded app)
/sbin/agetty —noclear Ss+ Background process (interruptible sleep and a session leader and is in foreground group)
ps aux R+ Running foreground process

Use the following command to list Linux processes along with pid, user name, stat as follows:
ps -eo pid,user,stat,comm
You can combine ps with grep command command as follows:
ps -eo pid,user,stat,comm | grep nginx

Источник

How to check running process in Linux using command line

I am a new system administrator for the Linux operating system. How do I check running process in Linux using the command line option?

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux terminal
Est. reading time 4 mintues

One can use the Linux command line or terminal app to display a running process, change their priorities level, delete process and more. This page shows how to use various commands to list, kill and manage process on Linux.

Check running process in Linux

The procedure to monitor the running process in Linux using the command line is as follows:

  1. Open the terminal window on Linux
  2. For remote Linux server use the ssh command for log in purpose
  3. Type the ps aux command to see all running process in Linux
  4. Alternatively, you can issue the top command or htop command to view running process in Linux

Let us see some example and usage in details.

Please note that vivek@nixcraft:

$ is my shell prompt. You need to type commands after the $ prompt.

How to manage processes from the Linux terminal

The ps command is a traditional Linux command to lists running processes. The following command shows all processes running on your Linux based server or system:
vivek@nixcraft:

$ ps -aux
vivek@nixcraft:

  1. root – User name
  2. 1 – PID (Linux process ID)
  3. 19:10 – Process start time
  4. /sbin/init splash – Actual process or command

There may be too many processes. Hence, it uses the following less command/more command as pipe to display process one screen at a time:
vivek@nixcraft:

$ ps -aux | more
vivek@nixcraft:

$ sudo ps -aux | less
Press q to exit from above Linux pagers. You can search for a particular Linux process using grep command/egrep command:
vivek@nixcraft:

$ ps aux | grep firefox
vivek@nixcraft:

$ sudo ps aux | grep vim
vivek@nixcraft:

$ sudo ps -aux | egrep ‘sshd|openvpn|nginx’

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Linux pgrep command

Many variants of Linux comes with the pgrep command to search/find process. The syntax is:
vivek@nixcraft:

$ sudo pgrep sshd
vivek@nixcraft:

$ pgrep vim
vivek@nixcraft:

$ pgrep firefox
vivek@nixcraft:

Linux top command

The top command is another highly recommended method to see your Linux servers resource usage. One can see a list of top process that using the most memory or CPU or disk.
vivek@nixcraft:

$ sudo top
vivek@nixcraft:

Linux htop command to check running process in Linux

The htop command is an interactive process viewer and recommended method for Linux users. One can see a list of top process that using the most memory or CPU or disk and more:
vivek@nixcraft:

$ sudo htop
vivek@nixcraft:

Linux kill command

Want to kill a process? Try kill command. The syntax is:
vivek@nixcraft:

$ kill pid
vivek@nixcraft:

$ kill -signal pid
Find PID using ps, pgrep or top commands. Say you want to kill a PID # 16750, run:
vivek@nixcraft:

$ kill 16750
For some reason if the process can not be killed, try forceful killing:
vivek@nixcraft:

$ kill -9 16750
OR
vivek@nixcraft:

$ kill -KILL 16750

Linux pkill command

If you wish to kill a process by name, try pkill command. The syntax is:
vivek@nixcraft:

$ pkill processName
vivek@nixcraft:

$ pkill vim
vivek@nixcraft:

$ pkill firefox
vivek@nixcraft:

$ pkill -9 emacs
vivek@nixcraft:

$ sudo pkill -KILL php7-fpm

Linux killall command

The killall command kills processes by name, as opposed to the selection by PID as done by kill command:
vivek@nixcraft:

$ killall vim
vivek@nixcraft:

$ killall -9 emacs

Linux nice and renice command

The primary purpose of the nice command is to run a process/command at a lower or higher priority. Use the renice command to alter the nice value of one or more running Linux processes. The nice value can range from -20 to 19, with 19 being the lowest priority. Say, you want to compile software on a busy Linux server. You can set a very low priority, enter:
vivek@nixcraft:

$ nice -n 13 cc -c *.c &
Set a very high priority for a kernel update. Before rebooting Linux server, run:

Источник

How To Use ps, kill, and nice to Manage Processes in Linux

Published on September 6, 2013

Introduction

A Linux server, like any other computer you may be familiar with, runs applications. To the computer, these are considered “processes”.

While Linux will handle the low-level, behind-the-scenes management in a process’s life-cycle, you will need a way of interacting with the operating system to manage it from a higher-level.

In this guide, we will discuss some simple aspects of process management. Linux provides an abundant collection of tools for this purpose.

We will explore these ideas on an Ubuntu 12.04 VPS, but any modern Linux distribution will operate in a similar way.

How To View Running Processes in Linux

The easiest way to find out what processes are running on your server is to run the top command:

The top chunk of information give system statistics, such as system load and the total number of tasks.

You can easily see that there is 1 running process, and 55 processes are sleeping (aka idle/not using CPU resources).

The bottom portion has the running processes and their usage statistics.

An improved version of top , called htop , is available in the repositories. Install it with this command:

If we run the htop command, we will see that there is a more user-friendly display:

How To Use ps to List Processes

Both top and htop provide a nice interface to view running processes similar to a graphical task manager.

However, these tools are not always flexible enough to adequately cover all scenarios. A powerful command called ps is often the answer to these problems.

When called without arguments, the output can be a bit lack-luster:

This output shows all of the processes associated with the current user and terminal session. This makes sense because we are only running bash and ps with this terminal currently.

To get a more complete picture of the processes on this system, we can run the following:

These options tell ps to show processes owned by all users (regardless of their terminal association) in a user-friendly format.

To see a tree view, where hierarchal relationships are illustrated, we can run the command with these options:

As you can see, the process kthreadd is shown to be a parent of the ksoftirqd/0 process and the others.

A Note About Process IDs

In Linux and Unix-like systems, each process is assigned a process ID, or PID. This is how the operating system identifies and keeps track of processes.

A quick way of getting the PID of a process is with the pgrep command:

This will simply query the process ID and return it.

The first process spawned at boot, called init, is given the PID of “1”.

This process is then responsible for spawning every other process on the system. The later processes are given larger PID numbers.

A process’s parent is the process that was responsible for spawning it. Parent processes have a PPID, which you can see in the column headers in many process management applications, including top , htop and ps .

Any communication between the user and the operating system about processes involves translating between process names and PIDs at some point during the operation. This is why utilities tell you the PID.

Parent-Child Relationships

Creating a child process happens in two steps: fork(), which creates new address space and copies the resources owned by the parent via copy-on-write to be available to the child process; and exec(), which loads an executable into the address space and executes it.

In the event that a child process dies before its parent, the child becomes a zombie until the parent has collected information about it or indicated to the kernel that it does not need that information. The resources from the child process will then be freed. If the parent process dies before the child, however, the child will be adopted by init, though it can also be reassigned to another process.

How To Send Processes Signals in Linux

All processes in Linux respond to signals. Signals are an os-level way of telling programs to terminate or modify their behavior.

How To Send Processes Signals by PID

The most common way of passing signals to a program is with the kill command.

As you might expect, the default functionality of this utility is to attempt to kill a process:

This sends the TERM signal to the process. The TERM signal tells the process to please terminate. This allows the program to perform clean-up operations and exit smoothly.

If the program is misbehaving and does not exit when given the TERM signal, we can escalate the signal by passing the KILL signal:

This is a special signal that is not sent to the program.

Instead, it is given to the operating system kernel, which shuts down the process. This is used to bypass programs that ignore the signals sent to them.

Each signal has an associated number that can be passed instead of the name. For instance, You can pass “-15” instead of “-TERM”, and “-9” instead of “-KILL”.

How To Use Signals For Other Purposes

Signals are not only used to shut down programs. They can also be used to perform other actions.

For instance, many daemons will restart when they are given the HUP , or hang-up signal. Apache is one program that operates like this.

The above command will cause Apache to reload its configuration file and resume serving content.

You can list all of the signals that are possible to send with kill by typing:

How To Send Processes Signals by Name

Although the conventional way of sending signals is through the use of PIDs, there are also methods of doing this with regular process names.

The pkill command works in almost exactly the same way as kill , but it operates on a process name instead:

The above command is the equivalent of:

If you would like to send a signal to every instance of a certain process, you can use the killall command:

The above command will send the TERM signal to every instance of firefox running on the computer.

How To Adjust Process Priorities

Often, you will want to adjust which processes are given priority in a server environment.

Some processes might be considered mission critical for your situation, while others may be executed whenever there might be leftover resources.

Linux controls priority through a value called niceness.

High priority tasks are considered less nice, because they don’t share resources as well. Low priority processes, on the other hand, are nice because they insist on only taking minimal resources.

When we ran top at the beginning of the article, there was a column marked “NI”. This is the nice value of the process:

Nice values can range between “-19/-20” (highest priority) and “19/20” (lowest priority) depending on the system.

To run a program with a certain nice value, we can use the nice command:

This only works when beginning a new program.

To alter the nice value of a program that is already executing, we use a tool called renice :

Note: While nice operates with a command name by necessity, renice operates by calling the process PID

Conclusion

Process management is a topic that is sometimes difficult for new users to grasp because the tools used are different from their graphical counterparts.

However, the ideas are familiar and intuitive, and with a little practice, will become natural. Because processes are involved in everything you do with a computer system, learning how to effectively control them is an essential skill.

Источник

Читайте также:  Как посмотреть историю mac os
Оцените статью