The Linux operating system has been developed with a series of processes which allow both the applications and the parameters of the system to run without problems according to their respective task. It is necessary that we understand that each process carries out an action in particular, some processes will allow us to connect to the network, others will make it possible for us to access programs, etc., so that if something happens with a process it may harm certain actions to be carried out about this. The processes are represented by those programs that are running and are identified through the PID or process number that is assigned when it is executed or started..
When different users can access the system , as is normal, it can happen that someone has opened a file and makes it impossible for us to access this process. Another thing you have to tell is that if we name you "file" our mind imagines a text document, an image, a spreadsheet, etc., but in Linux operating systems a file goes far beyond this concept and that there a file can be:
Types of files
- Applications or programs and much more.
Do you see that Linux changes the way of thinking about the concepts? Therefore, it is more than necessary that we are able to understand how to access these files and processes in order to visualize which user has it running in real time and if it is possible to take the necessary actions as the case may be.
TechnoWikis will explain to you through this tutorial how we can perform the process of visualizing the processes and knowing in detail that the user has it open..
1. Use the lsof command to detect the use of files in Linux
The command lsof is a command integrated in Linux thanks to which we can obtain information about the files that are opened by processes in the system, that is, lsof is responsible for listing the files opened in the Linux distribution used.
To begin to understand its use we will execute the following line:
lsof / dev / null
The file / dev / null is a special file which is able to omit the information that is written in it as well as the information that is redirected to it.
As a result of this order, we will see details such as:
- Command used
- Process PID
- Active user
- Type of service
- Device
- Used node
Deploy only a user's processes
As it is natural that several users are acting simultaneously, we can apply a filter to display only the processes or files of a particular user, for example the user "TechnoWikis", for this we will use the -u parameter as follows:
lsof -u TechnoWikis
As a result, we find much more complete details about that particular user:
Show details of a protocol service
Since lsof is a very integral command, if we want to know in detail the processes or services of a certain protocol, for example, TCP, we will execute the following:
sudo lsof -i TCP
In case of defining a particular port we must execute the following:
sudo lsof -i TCP: 80
See current network activity
To visualize the network activity in real time in Linux we will execute the following line:
lsof -i
Validate services and ports
If the objective is to validate the services and / or ports that are listening, we should use the following line:
lsof -i -nP
View specific open files
If it is required to see the files opened by a specific process or program, the line to be used will be the following:
lsof -c cupsd
In order to observe the files that are open in a specific directory, we must add the -D parameter like this:
sudo lsof + D / etc
List files by addressing
To list the files based on the Internet address, we have the following options:
lsof -i 4 (IPv4 Addressing) lsof -i 6 (IPv6 Addressing)
2. Use the ps command to detect the use of files in Linux
As administrators of Linux on many occasions we must see all the active processes at that moment. This may be due to administrative or support tasks, to visualize the processes in Linux, just execute the ps (process status) command:
List processes initiated from shell
ps (this option only lists the processes that have been started from the current shell)
Access details of all processes
If we want to access the information of all processes, we must add the -A parameter:
ps -A
Deploy all processes
In addition to this, we can combine the parameters a, u and x together, with what purpose ?, Simple, deploy all the processes that are being executed for all users of the Linux distribution, as well as detailed information such as:
- The user name of the process
- The start time of the process
- Command with which the process was started
ps aux
TechnoWikis always gives you the best advice so that the information and management tasks are as complete as possible and thanks to these options we can know the processes and open files in Linux..