+3 votes
337 views
How to view active processes in Ubuntu

in Linux / Unix by (551k points)
reopened | 337 views

1 Answer

+4 votes
Best answer

1. Manage processes using PS in Ubuntu
2. Use the PGREP command in Ubuntu
3. Use the top and htop command in Ubuntu
4. Manage processes with KILL in Ubuntu
5. Use the PKILL command in Ubuntu
6. Use the NICE and RENICE commands in Ubuntu

The processes in Linux play a fundamental role within all the actions to be executed since these allow what services, applications and roles to be executed correctly. When a process presents some type of error, this is likely to trigger many other tasks to be affected resulting in a negative impact on many other areas. Sometimes it can happen that we find processes that suddenly stop and that we must find in order to finish it. Therefore, it is useful to know how to see the processes that are running and thus choose which ones we want to kill to avoid further failures..

As Linux system administrators we must make use of the integrated tools to manage the processes and through the terminal it will be possible to show a running process, change the level of priorities, eliminate processes and more actions on them.

Normally, when we want to see the processes in execution in Linux we use the “top” command that generates a complete list of the processes with details such as:

  • PID of the process.
  • User who has the process.
  • CPU, memory and other use.
image

TechnoWikis will explain other methods how we can validate and manage processes in Linux..

To keep up, remember to subscribe to our YouTube channel! SUBSCRIBE


1. Manage processes using PS in Ubuntu


The ps (process status) command is one of the most common since this command lists the running processes in real time.
Step 1

The basic execution of ps is as follows:
 ps -aux 
image
Step 2

As a result we obtain the following values:
  • User with the process.
  • PID of the process.
  • CPU and RAM memory usage.
  • TTY
  • Start time of the process.
  • Active time and more.
Step 3

Another option to use ps is as follows:
 sudo ps -a 
image
Step 4

We could see the processes of a particular user:
 sudo ps -U TechnoWikis 
image
Step 5

If the system has too many processes, it is possible to use the less and more command as a pipe to display the process on one screen at a time.
 ps -aux | more sudo ps -aux | them 
Step 6

It is also possible to search for a particular process using the following syntax:
 ps aux | grep "process" 
image
Step 7

Some of the parameters to use with the ps command are:
-TO
Shows all processes (of all users in the system).
-to
It shows all the processes of a given [tty].
-d
Show everything except the session leaders.
-and
Show all processes.
T
It shows all the processes of the current terminal.
to
It shows all the processes of the current terminal including those of other users.
g
Show all processes including leading groups.
r
Show only current processes.
x
It shows the processes in a BSD style (without controlling [TTY]).

2. Use the PGREP command in Ubuntu

Step 1

The pgrep command is a utility which takes a regular expression from the command line and is responsible for returning the ID of the processes whose name matches the indicated regular expression, its use syntax is:
 pgrep process 
Step 2

When executed, the result will be the PID of the processes associated with the search: image
Step 3

If we want to list both the PID and the process name we add the -l parameter :
 sudo pgrep -l process 
image

3. Use the top and htop command in Ubuntu


As we have mentioned, they are the most used commands for the whole process management issue in Linux, since both top and htop list the processes in real time with a series of analysis attributes.
Step 1

The basic top syntax is to execute:
 Top 
Step 2

As a result we will obtain all the processes with their attributes: image
Step 3

Something important about this top command is that vital information is displayed at the top for administrators such as:
  • Users quantity.
  • Number of tasks in real time.
  • How many processes are in hibernation or detained.
  • Memory and disk usage, etc.
Step 4

When using the top command, we will see summary information of the system, as well as a list of the tasks currently managed by the Linux kernel, something to keep in mind is that all the summary information of the system can be configurable by the user. Some of the parameters to use with top are:
-to
Sort by memory usage.
-b
Batch mode
c
command line / program name.
-d
delay time interval with values ​​such as -d ss.tt.
-H
Threads.
-h
top help.
-i
Inactive processes
-M
Detect memory units.
-m
VIRT / USED.
-n
Number of iterations
-s
Safe Mode.
-or
User analysis For example:
 top -u solvetic 
image
Step 5

Now, the htop command is a free process viewer (GPL) based on ncurses for Linux systems. Its operation is identical to top at the top, but the difference is that it will be possible to move vertically and horizontally in order to visualize all the processes running in the system. The associated command lines are displayed. For use, just run htop: image
Step 6

There we see the processes in an interactive way and some of the parameters we can use are:
-d –delay
Delay in between updates, in tenths of a second.
 -d –delay 
-C --no-color --no-color
Start htop in monochrome mode.
 -C --no-color --no-color 
-h –help
Access htop help.
 -h –help 
-u --user = USERNAME
Deploy only the processes of a specific user.
 -u --user = USERNAME 
-p Pag
This option works with threads for page map memory statistics.
 -p Pag 
-s --sort-key
Sort the data by the indicated column.
 -s --sort-key 
-v –version
Display htop help.
 -v –version 
image
Step 7

In addition to this, we can use the function keys like this:
F1
Help.

F1

F2
Configuration.

F2

F3
Search.

F3

F4
Filters

F4

F5
Tree View

F5

F6
Sort by.

F6

F7 / F8
Increase process priority.

/ F8 F7 / F8

F9
Kill a process

F9

F10
Get out of htop.

F10

Step 8

For example, if we use F2 we access all the configuration variables: image

4. Manage processes with KILL in Ubuntu

Step 1

The kill command has basically been developed to kill a conflicting process, its syntax is:
 kill pid kill -signal pid 
Step 2

For example:
 Kill 4220 
image
Step 3

The kill command sends a signal to a process, in case of not defining which signal to send, by default the TERM signal is sent which terminates the process. Some of the parameters to use are:
Show name
It is the name, the abbreviated name or the number of the signal to be sent, preceded by a hyphen.
 -s signal 
List names
See the list of available signal names.
 -l, --list [= signal] 
Signal Information
List the names and numbers of signals available in a table.
 -L, --table 
Step 4

The signs, along with their number are:
  • 1 HUP
  • 2 INT
  • 3 QUIT
  • 4 ILL
  • 5 TRAP
  • 6 APRT
  • 7 BUS
  • 8 FPE
  • 9 KILL
  • 10 USR1
  • 11 SEGV
  • 12 USR2
  • 13 PIPE
  • 14 ALRM
  • 15 TERM
  • 16 STKFLT
  • 17 CHLD
  • 18 CONT
  • 19 STOP
  • 20 TSTP
  • 21 TTIN
  • 22 TTOU
  • 23 URG
  • 24 XCPU
  • 25 XFSZ
  • 26 VTALRM
  • 27 PROF
  • 28 WINCH
  • 29 POLL
  • 30 PWR
  • 31 SYS
Step 5

For example, to finish a process we can execute:
 kill -15 4220 

5. Use the PKILL command in Ubuntu


The pkill command searches for or signals processes based on name and other attributes.
Step 1

Its general syntax is:
 pkill [-signal] [-fvx] [-n | -o] [-P ppid, ...] [-g pgrp, ...] [-s sid, ...] [-u euid, ...] [-U uid, ...] [-G gid, ...] 
Step 2

The pkill command is responsible for sending the specified signal which is by default SIGTERM, to each process instead of listing them on the standard output. Its basic execution is:
 pkill "process" 
image
Step 3

Some of the parameters to use are:
Delimit ID
defines the string used to delimit each process ID in the output.
 -d delimiter 
Compare pattern
Makes the pattern only compare to the name of the process.
 -F 
Match processes
Makes the processes match in the process group identifications listed.
 -g pgrp 
Processes with real ID
Only the processes whose real group ID is listed are the same.
 -G gid 
List process
List the process name, as well as the process ID.
 -l 
Killed process
display which process has been killed.
 -I have done 
Count the same processes
Count the matching processes.
 -c count 
Use whole name
makes use of the full name of the process for matches.
 -f full 
New processes
Select the most recent processes.
 -n newest 
Old processes
Select the oldest processes.
 or oldest 
Match ID
Match the session IDs.
 -s session 
Choose order
Select with the indicated sort name and more.
 -x exact 

6. Use the NICE and RENICE commands in Ubuntu


The main purpose of the nice command is to execute a process or command with a lower or higher priority than the default one, while with the renice command, the original nice value can be altered.
Step 1

Values ​​can vary from -20 to 19, with 19 being the lowest priority. The syntax to use is:
 renice {Priority} -p {PID} 
Step 2

For example, we will identify the processes with pgrep and then assign priority with renice. As we can see, the new priority for the selected process has been established.
 pgrep VBoxClient sudo renice 934 12 
image

As we can see, the options to manage, manage and control the processes in Ubuntu will be a relatively simple task thanks to each of the commands described and each of them will display valuable information for each administrative support task.


by (3.5m points)
edited

Related questions

+5 votes
1 answer
asked Sep 22, 2019 in Linux / Unix by backtothefuture (551k points) | 267 views
+5 votes
1 answer
+4 votes
1 answer
asked Oct 15, 2019 in Linux / Unix by backtothefuture (551k points) | 199 views
+5 votes
1 answer
asked Oct 11, 2019 in Linux / Unix by backtothefuture (551k points) | 289 views
+3 votes
1 answer
Sponsored articles cost $40 per post. You can contact us via Feedback
10,643 questions
10,775 answers
510 comments
3 users