Monitorizarea

Using ps command on linux

Using ps command on linux
The command “ps” will show the processes status as snapshot. In contrast with Microsoft Windows which shows processes status in live view. In Linux, if we want a live view of the processes we need to use the command top which we won't explain in this tutorial limited to ps.

Let's try to run ps without any additional parameter just by running:

ps

As we can see we have 4 columns:

PID: Process ID, shows the process identification number.

TTY: Identifies the terminal from which the process was executed.

TIME: Shows the processor's time occupied by the program.

CMD: Shows the command used to launch the process.

The ps default output without parameters as you can see will only list the processes executed by root.

If we want to check the processes ran by every user then run:

ps -a

Now we can see the processes executed by all users.  Usually when we use the command ps we add parameters like -a, -x and -u.

While -a lists processes started by all users, -x also lists processes started at boot like daemons, the parameter -u will add columns with additional information on each process:

ps -axu

We can see now all processes, executed by all users, by the system itself and we also got additional information on each process:

USER: Specifies the user who executed the program.

PID: Process ID, shows the process identification number.

CPU%: The processor % used by the process.

MEME%: The memory % used by the process.

VSZ: The virtual size in kbytes.

RSS: In contrast with the  virtual size, this shows the real memory used by the process.

TTY: Identifies the terminal from which the process was executed.

STATE: Shows information on the process' state just as it's priority, by running “man ps” you can see codes meaning.

START: Show when the process has started.

TIME: Shows the processor's time occupied by the program.

CMD: Shows the command used to launch the process.

To list the processes executed by a specific user you can run:

ps -U username

After we understood how to use ps to show processes, let's check how to stop them.

In Linux the command kill is the one used to stop processes. We can run “kill PIDNUMBER” to stop a process:

As you can see, I killed a process started by Gimp, but if we run ps -axu again we'll see Gimp is still running:

What we need to do to assure the program's closure is to kill all it's processes, including parent processes, we can do it by adding the parameter -9:

kill -9 PIDNUMBER

As you can see this time the process was killed, since I tried to kill it twice and the second time the system told me the process wasn't available, we can run ps -axu again to be sure:

The command killall can be used to kill all processes associated with a program's name:

As you can see in the image above LibreOffice is running now, let's see what happens when I run:

killall soffice.bin


Let's check ps -axu again:


As we can see LibreOffice was closed.

I hope you found this article useful to manage Linux processes. Keep following us on LinuxHint for more tips and updates on Linux.

AppyMouse On-screen Trackpad and Mouse Pointer for Windows Tablets
Tablet users often miss the mouse pointer, especially when they are habitual to using the laptops. The touchscreen Smartphones and tablets come with m...
Middle mouse button not working in Windows 10
The middle mouse button helps you scroll through long webpages and screens with a lot of data. If that stops, well you will end up using the keyboard ...
How to change Left & Right mouse buttons on Windows 10 PC
It's quite a norm that all computer mouse devices are ergonomically designed for right-handed users. But there are mouse devices available which are s...