Categories: Process

Linux commands: complete guide to managing processes

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!

What are Linux Commands

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.

There are basic Linux commands for all uses!

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.

Understand the importance of learning 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 for process management

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!

What is a process in Linux?

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.

Signs of processes in Linux

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.

Commands for controlling background processes

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.

1. Jobs command

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.

2. Bg command

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.

3. Fg 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.

4. Nohup command

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.

Commands for modifying execution priority

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.

5. Nice command

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.

6. Renice Command

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:

  • -p: Get a PID to change its priority.
  • -u: Receives a username to change the priority of all processes running on this user.
  • -g: Receives a name from a group to change the priority of all processes belonging to this group.

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.

Other commands for process management

There are also other commands for managing processes in Linux, namely:

  • ps command;
  • command pstree;
  • top command.

In general, these commands are related and serve to demonstrate or make it possible to visualize the processes in execution and their respective attributes.

7. PS command

Use:

$ ps [options]

The ps command generates a list of all running processes and their attributes.

The most common options are:

  • -a: shows the processes running by all users. Normally, it shows only the processes belonging to the user who executed ps;
  • -u: shows the list of processes including the name of the users who own the processes and the start of executions, percentage of CPU used, percentage of memory used and associated terminal;
  • -x : shows the list of processes that do not have a terminal associated with it. Useful for viewing server processes (daemons);
  • f: shows processes in the form of a tree. Very useful for identifying the parent-child process relationship between the processes in execution.

See the ps command help for more options.

8. pstree command

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.

  • -a: This option shows the command line used to start the processes;
  • -c: Disables the function of merging identical processes at the same hierarchy level;
  • -G: Uses the VT100 format to show the lines between processes in place of the keyboard characters;
  • -h: Highlights the processes connected to the terminal at the exact moment;
  • -p: Includes the PID of the processes in the list.

If you want to see processes running in a dynamic way, such as the Windows “Tasks”, Linux has the top command.

9. 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:

  • -b: execute in batch mode or batch file. It is used to direct the output of the command to another process or to a file;
  • -d n: determines the time of screen updates in n seconds. The default is five seconds;
  • -n num: shows the number of times the updates of the processes running on the screen are updated and then terminated. Useful to be used with the —b;
  • -q option: run with updates in real time. This option should be used with caution because it can consume a large amount of CPU;
  • -u: Monitors the processes running by a particular user;
  • -p: monitors a particular process identified by its PID. More than one process can be defined with this option.

The top command may also support some commands that alter its behavior during execution. They are:

  • Z: Change the color scheme of the top. For this option to be active, the terminal must support ANSI;
  • F: Add columns with more process monitoring options;
  • u: Shows the processes of a particular user;
  • k: Terminates (kills) with a particular process;
  • r: Changes the process execution priority (renice);
  • R: Changes the order of processes according to CPU usage;
  • q: Exits interactive top mode.

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.

Commands to stop running processes

If your goal is to stop one or more processes that are currently running, just try one of these commands:

  • kill command;
  • killall command;
  • pkill command;
  • or pgrep command.

All of them have the purpose of stopping or terminating as many processes as necessary in a direct and elegant manner.

10. Kill command

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.

11. Killall command

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.

12. Pkill command

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

13. pgrep command

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.

Linux commands for system control and access

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:

  • exit: is the command that ends the session on the command line;
  • logout: is the command that closes the session being used, but only in the C shell and in the bash shell; passwd: is
  • used to edit the password of the logged in user;
  • yppasswd : allows the user to change the user’s password on the yellow pages;
  • rlogin: is used to securely log in to a Linux system;
  • slogin: logs in to Linux systems in a highly secure manner;
  • ssh: used to open a session secure, especially on remote servers.

Linux commands for communication

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:

  • mail: command that opens an interface for exchanging e-mails;
  • mesg: used to allow or not the exchange of messages via a terminal between computers active on the network;
  • pine: is also useful for sending and receiving e-mails;
  • talk : this command allows you to talk with other users on your network;
  • write: is used to send short messages to active users on your network.

Main Linux commands

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:

  • nano: edit text files, notepad style;
  • watch: command responsible for scheduling the repetition of some other command;
  • script: is capable of programming the execution of some commands, with a time interval or not;
  • cd : used to show the directory where a file is located;
  • ls: command that displays all existing files and filters them by characters;
  • rm: removes files according to the user’s approval;
  • find: also serves to find files, from anywhere on the computer.

These commands have a series of rules and subcommands for more specific execution. All of this information is contained in another blog of ours. 

Linux commands for everyday life

As mentioned before, Linux commands help with everyday activities.

See the main Linux commands for everyday life:

rm command

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:

  • -f: removes files without asking for authorization;
  • -i: removes the file and directory;
  • -r, -R: removes the file according to the user’s authorization;
  • -d, -dir: removes directories that have no files.

ls command

The ls command displays existing files according to a character filter.

The filters are selected from subcommands listed below:

    • -color=auto: separates files by color;
    • -A, -almost-all: displays files from all files, except for entries “.” and “..”

;

  • -a, -all: display all files, hidden or not;
  • -m: displays files separated by commas.

Cat command

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! .

Command vi

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!

Df command

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.

Top command

The top command shows hard disk storage information, mainly the amount of RAM.

Cd command

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.

Understand more about Linux processes

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.

Understand states and sequence of execution of a process

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:

  • Executable;
  • Sleeper;
  • Stopped;
  • and Zombie.

You need to know each process carefully to assertively manage the sequences.

Executable

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.

Sleeping

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”.

Stall

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”.

Zombies

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.

Attributes of processes (programs) in Linux

It is important that you understand that each program is at least a process and that each process has certain attributes, such as:

Process ID (PID) or process identification

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;

User ID and Group ID (User ID and Group ID)

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;

Parent Process

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;

Environment variables

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.

Work directory

The processes are also associated with a working directory, where they can read and write the disk;

Timers

The Kernel keeps records of the time when processes are created as well as the CPU time that they consume during their execution.

Conclusion

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.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Share
Published by
Uirá Endy Ribeiro

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.