Do you know how to execute commands to manage processes on Linux? This is a natural difficulty for all beginning or even intermediate users and programmers in the Linux universe.
Knowing which commands should be used for each function is the responsibility of those who use Linux as their environment and work tool.
In addition, it is also your responsibility to analyze what processes are running and to balance them so that the Linux processor or Kernel is not overloaded.
All of these points are not knowledge acquired “overnight”, but are learned over time by studying which are the best Linux commands.
With that in mind, the Linux Certification team developed this complete content, with everything you need to know about listing processes in Linux and managing them assertively.
In this article, you will find the main Linux commands for process management and for various other functionalities.
To obtain all the information that we have separated, simply continue reading. Check it out!
Linux is an operating system widely used by programmers, but also by ordinary users in simpler activities.
Because it is an open source system, there are numerous ways to use Linux and, therefore, there are several Linux commands.
Linux also has a number of systems, such as Ubuntu, Fedora, Debian, Mint, and others. In this way, the list of commands is extended even further.
Linux commands seek to facilitate the execution of actions and processes within the Linux operating system, which can be very useful for all user profiles.
Within the command line, also known as a prompt, simply type the command for a process that you want to execute and then it starts.
Basic Linux commands can be used for a variety of purposes. Many people who work with IT use Ubuntu and Fedora, which are part of Linux.
Thus, to be able to explore all the tools that these systems have to offer, it is necessary to know basic commands.
Not only people who work with technology, but also ordinary users can make use of Linux.
The only thing a person who wants to optimize their processes with Linux needs to do is migrate to a command line interface (CLI).
Most versions of Linux use the graphical user interface (GUI), which is aimed at everyday users.
Thus, to use basic or advanced Linux commands, it is necessary to learn at least how to access the CLI.
But don’t worry. In this content, we have separated a complete guide to get you mad at Linux commands.
Learning the basic Linux commands is essential to improve your work, if that is the reason why you use the operating system.
The content that teaches how to use Linux in more depth is aimed at those who already know how to use shell commands, that is, those who have advanced from a simple graphical user interface.
This means that those who understand Linux commands have greater access to operating system information.
The commands improve the work of technology professionals and also highlight them in relation to other workers who also use the system, but in a less applied way.
Linux commands are useful for various activities, such as process management. This is because the commands are able to make actions carried out in a practical way.
It is undeniable that, for this reason, Linux is widely used by developers in different companies.
In addition to being an open source operating system, Linux is versatile and built through an open community.
Do you want to start learning about Linux commands or deepen your studies? This article will help you with that!
Any action running on the Linux system can be classified as a process and, as such, needs to be managed.
This management only takes place through specific commands, which determine when the process will stop, be in the background, or start.
Those who administer Linux need to know the commands like the back of their hand in order to know how to control and pause them when necessary.
It is also possible to create “layers” for executing processes, placing the most important and main ones in the foreground and the others in the background.
In this way, the Linux Kernel will not be overloaded and its capacity will not be impaired.
After all, some processes may be too “selfish” and end up exhausting the full potential of the processor, which is left without sufficient resources for the rest of the applications.
This only happens because Linux is able to manage processes effectively, with real multiprocessing, as long as it receives the right commands.
In Linux, processes are defined by their owner, by their status (whether running or paused, for example), by the priority of execution, and by the resources they require.
Every process in Linux listens to signals. These signals are used by the Kernel, by other processes, or by the user to warn a particular process about a particular event.
UNIX guru W. Richard Stevens describes the signals as software interruptions.
When a signal is sent to a process it takes a certain action depending on the value that signal carries. Each sign has a unique name and a numerical value.
Linux has over 30 defined signals. Most are used by Kernel and some are used by users. Observe the most important ones, their values and their actions:
Signal | Numerical Value | Action |
---|---|---|
HUP | 1 | Hang-Up or shutdown. This signal is used automatically when you disconnect from a session or close a terminal. It is also used by server processes to invoke the rereading of the configuration file. |
KILL | 9 | End the process unconditionally quickly and drastically. This type of signal can leave open files and corrupted databases. It should be used if the process stops responding or in an emergency. |
TERM | 15 | ends the process in an elegant manner, allowing it to close files and execute its end-of-execution routines. |
TSTP | 20 | Terminates execution to continue later. This signal is sent automatically when we use the ctrl-z keys. It is used to put the process in the background. |
The understanding of signals is important to know how the system interacts with the processes in execution.
Like other complete operating systems, Linux allows us to place processes in the background.
For a process to run in the background, it must not wait for any user action, for example: wait for a subcommand.
In this state the process will communicate with the user through the signals.
Basically, to place any process in the background of execution, simply add the “&” character at the end of the command line that will execute the process:
$ find/-name *.conf > lista_arquivos_configuracao.txt &
The find command will run in the background and its output will be directed to the lista_arquivos_configuracao.txt file.
Use:
$ jobs [options]
The jobs command lists processes running in the background. If a task number is provided the command will return information relevant only to the task in question.
The task number is provided when the process is placed in the background.
The most common options are:
-l Lists the PID of the background processes.
Use:
$ bg [task_number]
The bg command puts a running process in the background. Placing the “&” sign after the command call has the same effect.
If a command is already running in the foreground, i.e. connected to a terminal, we can temporarily interrupt its execution with the TSTP (18) signal by pressing the ctrl-z keys and activating it immediately after the bg command.
Use:
$ fg [task_number]
The fg command does the exact opposite of the bg command, placing the task in the foreground and linked to a terminal.
Use:
$ nohup [command]
The nohup utility executes the specified command without tethering it to any terminal, immune to crashes, connection drops, and intentional disconnections.
Example:
$ nohup find//-name uira* > files_found &
In this example, nohup will execute the command find/-name uira*
and send the output to files_found, which will run in the background.
The Linux Kernel has process scheduling as one of its critical activities.
This scheduler is a special algorithm that queues all running processes and decides which process will be executed and for how long.
The scheduler is what allows the computer to execute more than one concurrent process, dividing the CPU into slices of execution time.
The implementation of the scheduler is so important that it is what really makes the difference in modern operating systems.
Linux allows the user to interfere with the priority of executing processes, freeing up more or less CPU time.
The list of priorities can be viewed with the ps —lax
command in the PRI column.
The higher the priority number, the more CPU time the process has and the more important it is. The lower the number, the less CPU time and the less importance.
It is possible to modify the execution priority of processes on Linux using the nice and renice commands. These commands are extremely useful in multi-user environments.
Imagine a server with many users logged in and each one running something.
In this type of environment, it is necessary to give more or less processing slices to the various user programs to maintain a stable and organized environment.
Use:
$ nice [-n prioritization_setting] [command]
The nice command adjusts a process’s available CPU time to higher or lower priority.
In English the word “nice” means “cool”. If the priority adjustment for a process is a positive number, it means that it is being cooler with the other programs reducing its priority.
If the adjustment is a negative number, it means that the program is being less cool, increasing its execution priority and leaving less CPU time left for other programs.
The possible priority adjustment ranges from —20 (highest priority/least cool) to 19 (coolest, least priority).
If no adjustment value is passed, the nice command will adjust the priority to +10, reducing the process execution time.
$ nice updatedb &
In this example, the updatedb command has lower execution priority.
$ nice —n —10 payroll
In this example, the payroll command will be executed with higher priority.
Use:
$ renice [+/-] prioritization_setting [options] PID/user
The renice command adjusts the execution priority of processes that are already running. By default, the renice command takes the PID of a particular process as a parameter.
The priority setting is an integer ranging from —20 (highest priority) to +20 (execute anything before this process).
The most common options are:
Example:
# renice -1 987 -u daemon root -p 32
In this example, the process number PID 987, PID 32, and all processes that daemon and root users own will have higher priority.
There are also other commands for managing processes in Linux, namely:
In general, these commands are related and serve to demonstrate or make it possible to visualize the processes in execution and their respective attributes.
Use:
$ ps [options]
The ps command generates a list of all running processes and their attributes.
The most common options are:
See the ps command help for more options.
Use:
$ pstree [options]
The pstree command will show the entire process tree from init to the last running process. It is similar to the ps —auxf
command.
It is useful for understanding the hierarchy of processes in Linux.
In addition to the options below, pstree can show the hierarchy pertaining to a specific user or process through its PID.
If you want to see processes running in a dynamic way, such as the Windows “Tasks”, Linux has the top command.
Use:
$ top [options]
The top command shows processes running like the ps command but refreshing the screen.
This feature is useful for monitoring how one or more processes act in the system. This command also orders the processes that use the most CPU at the top of the screen.
The most used options are:
The top command may also support some commands that alter its behavior during execution. They are:
Now that you know how to list the processes, it’s time to learn how to stop the processes running with the kill and killall commands.
If your goal is to stop one or more processes that are currently running, just try one of these commands:
All of them have the purpose of stopping or terminating as many processes as necessary in a direct and elegant manner.
Use:
$ kill [—signal] PID
The kill command sends signals to processes. It is generally used to terminate the execution of processes identified by your PID.
If no specific signal is passed as a parameter, kill will send the TERM (15) signal to end the process in an elegant manner.
Use:
# killall [—signal] PROCESS_NAME
The killall command sends signals to processes and takes as a parameter not the process PID, but its name.
It is generally used to terminate the execution of processes that have several child processes running at the same time.
If no specific signal is passed as a parameter, killall will send the TERM (15) signal to finalize the process in an elegant manner.
It’s important that you understand the difference between the kill and killall commands. The former sends signals to one or more processes identified by the PID.
The second sends signals to all processes in the execution queue that have a certain name.
The signals sent by Kill and Killall can be passed by name or by the corresponding integer.
Use:
# pkill [expression]
The pkill command is analogous to the killall command. It can send signals to processes and takes an expression or process name as a parameter.
It is generally used to terminate the execution of processes that have several child processes running simultaneously. $ pkill mysqld
The pgrep command is a mix of ps and grep. Use:
# pgrep [expression]
The pgrep command allows you to search for expressions in the list of running processes and returns the PID of the process in question.
The Linux commands for system control and access are all those that log in, exit, and exchange systems.
Among the main commands of this type, we can mention:
Linux commands also facilitate a company’s communication. By entering some codes, it is possible to access communication channels quickly and conveniently.
Below are the main Linux commands for communication:
The main Linux commands are the simplest, which can be learned by novice users.
From a command reading terminal, provided by the Linux system itself, it is possible to enter the codes correctly and thus perform actions quickly.
We have separated a list of the main Linux commands for you:
These commands have a series of rules and subcommands for more specific execution. All of this information is contained in another blog of ours.
As mentioned before, Linux commands help with everyday activities.
See the main Linux commands for everyday life:
The rm command is responsible for deleting files from their appropriate directories.
The action can be performed in different ways, according to the subcommand selected by the user. Among the options are:
The ls command displays existing files according to a character filter.
The filters are selected from subcommands listed below:
;
The cat command is used to open a specific file. The syntax to use it is: cat [OPTION] [FILE]. A basic example would be cat arquivo.txt.
This command has several other features, which can be accessed from the man cat command! .
The vi command works to activate a text editor with a simple interface. Basically, through it it is possible to customize your text, edit and create new files.
To understand more about its other variations, read our blog!
The df command allows you to view the memory occupied on the hard drive currently in use.
In addition to their most basic use, there are subcommands such as df – a, which display the use of the hard disk and also information from fictitious systems.
The top command shows hard disk storage information, mainly the amount of RAM.
The purpose of this command is to show in which directory a file is located or to move it from one directory to another.
You need to build the command according to the file you want to view. To do this, enter cd [FOLDER/]. If the directory exists, it will open on your device.
In addition to understanding what Linux processes are, it is necessary to understand how they work.
There are several factors that we must take into account to understand Linux commands.
Below, we will teach you more about the states, the execution steps, and the programs of the Linux processes.
Are you still a bit confused? Read the sequence and we will clarify all the points raised here.
Once created, the process receives a classification, also called execution state, which defines whether it will be executed immediately or later.
These classifications serve to actually prioritize executions and prevent less important processes from interfering with essential ones.
With that in mind, know that there are 4 main states of the Linux processes:
You need to know each process carefully to assertively manage the sequences.
As its name suggests, an executable process is one that is able to be executed instantly.
In English, “running”, this process is prepared for execution and can be released without major problems, almost naturally.
It becomes part of the “ready queue” queue, or ready to run, just waiting to be activated by a certain command.
Unlike the previous one, the dormant process or “interruptible sleep”, in English, is inactive just waiting for something to happen before it can be executed.
Literally speaking, this process is dormant until some command wakes it up to perform its function at the appropriate time.
Unlike the executable processes, which we saw earlier, this type of process does not consume any CPU resources and is inactive for a specified time in another queue.
Once this process ends your sleep time (“sleep”), you return to the “ready queue”.
As its name suggests, the stalled process is literally stopped or frozen. It is not running at this time.
The original name of this process is “stopped” or “suspended”, and it is a result of the “stop” command requested by the user.
When the user issues another command, asking to finish the action (“resume”), this process returns to the waiting list or “ready queue”.
It is possible, within a process hierarchy, for a given child process to terminate for some unexpected reason, and the parent process becomes a zoombie or defunct process.
Zoombie processes cannot be terminated with the kill command, because they no longer exist.
This is because each process created is assigned a place in the Kernel process table. When it is finished, your place in the Kernel table receives the result of your execution.
The result of the execution is retained in the table until someone queries it when it is then removed from the table.
The process state is called “zombie” when it is finished and its result has not yet been removed from the Kernel table.
Another special possibility is when any process that created new child processes that run below its hierarchy ends unexpectedly.
In this case, child processes lose their parent process and are adopted by the init process (PID 1), which is the parent of all processes. Observe the hierarchy between processes with the pstree —c —p
command.
These two situations described are not normal and may be caused by bugs in the programs.
It is important that you understand that each program is at least a process and that each process has certain attributes, such as:
Each process has a unique identification number. The first init process will always have PID 1 and for the rest of the processes this number increases as new processes are executed;
Processes must be executed with the privileges of a user account and the group associated with them. This is important because this way the system can determine and manage access to resources;
On Linux, no process runs independently of the others. All processes in the system, with the exception of init, have a parent process responsible for their execution.
The parentID attribute records the PID of the parent process. If the parent process finishes its execution before the child process, the child process is “sponsored” by init, earning a Parent ID equal to 1;
Each process inherits from its parent process some environment variables that simply hold certain values that may or may not be important to the running process.
It is possible that during its execution, a process changes, increases, or deletes an environment variable.
A child process can inherit variables from a parent process. But a parent process is unable to access variables created or changed by its children.
The processes are also associated with a working directory, where they can read and write the disk;
The Kernel keeps records of the time when processes are created as well as the CPU time that they consume during their execution.
Did you notice how important it is to know all the main commands to execute Linux processes?
Creating, verifying, pausing, and managing processes on Linux is essential for the proper functioning of the processing and system and, in addition, for the success of your work.
This is the only way to guarantee the best possible execution in an optimized and balanced way on your Linux.
All articles have the same purpose: to help you become an increasingly up-to-date, competent and developed professional capable of gaining significant space in the labor market.
The sudo command on Linux executes a given command as if it were another user.…
The ss command on Linux is extremely useful for investigating sockets, providing various information about…
Free Linux command shows the amount of total memory in use and available, as well…
The shell has structures for testing conditions and executing certain program sequences several times (loop),…
The /etc/fstab file stores the configuration of which devices should be mounted and what is…
The Netcat Command in Linux or nc is a utility used to do “almost anything”…
This website uses cookies.