LPI 010-150 – Investigating and Managing Processes

  1. Describe how to manage processes

In this lesson we will learn Linux process. The process is a set of instructions loaded into the memory. For example if we run the firefox, then the firefox is considered as a process and each process has process ID used to identify the process and etsy process has UID and GID and Se Linux context which determine the file system access level and these attributes normally inherited from the executing user. If we run PS command it will display the processes from the current terminal by default and if we add a option it will display all processes on all terminals. Here it’s the process ID which identify the process, and here it’s the terminal on which this process is running.

In the first command it will display the process which are running in the terminal pts zero and in the second command it will display all the process which are running in or terminal Pts zero and Pts one. And here we can see the process name or the command name. For example the first process is running su command and the second process is running shell, and the third process is running firefox process. If we add U option it will display the process owner information. Here in this column we can see who is running the process.

For example this process the first process is running by the root user and the bash shell process is running by MSC in user and SCU process or command is running by root user. In the second column which define the process ID PID we can see the process ID for each process. And in these columns we can see the resources which are used by each process. For example the first process is consuming 0. 5% from the CPU and 1. 6 percentage from the memory.

And here we can see the start date and the time for the process. And in the last column we can see the process name for each process. If we add x option in the PS command we will see the list of the processes which are running on the operating system which are not attached to specific terminal such as this process. We can see that here is question mark. It means this process is running in the background. It means it’s not attached to any terminal and we can use pipe character to redirect the output of the PS command and use it as input for less command. Now we can see the output of PS command page pipe. Here we can see the TTY.

  1. top

To know the current running processes, we can use top command. Here we can see many information about the current running processes and the load on the operating system. For example, here we can see that the uptime information which displays how many days and hours the system is up and running. And here we can see the number of logged in users and the load average defines the load on the CPU and it should be less than the number of the CPUs. And in the task we can see the number of total TaskUs and we can see that we have only one running TaskUs and 220 Tuscas are sleeping. And in this line we can see the usage of the CPU. For example, this percentage defines the CPU usage for the users and this one defines the CPU percentage used by the operating system.

And in this line we can see the memory usage, the total memory size and the free memory size and the US memory. And in the last line we can see the swept information, the total swap size, the free size of the swept and the used swept size. And here we can see information about the running processes such as the process ID, the user who is running the process and priority, and Nice which defines the priority of the process in the CPU. And here we can see the resources which are used by each process. And time defines the time of the process and the command defines the command name or the process name. To exit from the top command we will press Q to display the name of the current terminal. We can use Pty command here. It will display that the current terminal is Pts Zero. We can use three M command to display the memory usage. Here the first line display the memory usage and the second line display the swap usage.

  1. Exit Status Part 01

In this lesson we will learn the exit status in Linux any process reports success or failure with an exit status zero for success and nonzero for failure. So for example, if we run LS, this command is run successfully and its exit status is saved in dollar sign question mark. So to know the exit status of the last recent command we will execute echo dollar sign question mark here it’s zero. It means the most recent command has been run successfully, which is Les command. Let’s run LS XYZ command.

This command is failed because we don’t have XYZ file or directory in the current working directory. So if we echo the exit status of this command using echo dollar sign question mark, we will see that its value is two, which is not zero because the most recent command has been failed, which is LS XYZ. So to summarize the exit status will be zero for the successful command and will be not zero for the failed command and the exit status is stored in dollar sign question mark and to know the value of the exit status we can run echo dollar sign question mark.

  1. Exit Status Part 02

The commands can be run conditionally based on the exit status. So for example, if we run las, then double and operator then DF dash, this command means that DFH will be executed if the las command is run running successfully. So double end sign means if the exit status of the first command which is LS is equal zero, the second command will be run. So if we press Enter, we will see the output of LS command which lists the content of the current working directory which is tilde, which is the home directory of the login user root. And this is the output of the DFH command which display the space of our storage. So let’s execute the same command using LS XYZ, we will see that the command will not run successfully. Because double and sign means if the first command is run successfully and its exit status equals zero, then run the second document which is DFH command.

So since the first command is not running successfully, the second command will not run. Here we can see that there is error is coming from the first command that defines no such file or directory with name X-Y-Z. But if we run the same command using double pipe instead of double and operator, we will see that the command will run because double operator represent this conditional, or else it means if the first command is failed and its exit status not equal zero, then run the second command which is DFH.

Now we can see that the first command is filled with this error message. That’s why the second document is run successfully. To summarize, when we use double and operator, it means the first command should be run successfully. To run the second command and the double pipes means the first command should be filled to run the second command.

img