Linux Check if Process Is Already Running if So Do Not Start Again

Linux List Processes – How to Check Running Processes

Every day, developers utilize various applications and run commands in the terminal. These applications can include a browser, lawmaking editor, last, video conferencing app, or music player.

For each of these software applications that you lot open up or commands you run, information technology creates a process or task.

One beautiful feature of the Linux operating system and of mod computers in full general is that they provide support for multitasking. And so multiple programs can run at the same fourth dimension.

Have you ever wondered how you can cheque all the programs running on your machine? Then this article is for you, as I'll show yous how to list, manage, and kill all the running processes on your Linux machine.

Prerequisites

  • A Linux distro installed.
  • Bones knowledge of navigating around the control-line.
  • A smile on your face :)

A Quick Introduction to Linux Processes

A procedure is an case of a running computer plan that you can detect in a software awarding or command.

For instance, if you open up your Visual Studio Code editor, that creates a process which will merely stop (or die) once you lot cease or close the Visual Studio Code awarding.

Likewise, when y'all run a command in the terminal (like curlicue ifconfig.me), it creates a process that will only terminate when the command finishes executing or is terminated.

How to Listing Running Processes in Linux using the ps Command

Y'all can list running processes using the ps command (ps means process status). The ps command displays your currently running processes in real-time.

To test this, just open your final and run the ps command like and then:

Screenshot-2021-06-28-at-3.25.33-PM

This volition display the process for the current shell with four columns:

  • PID returns the unique process ID
  • TTY returns the final blazon yous're logged into
  • TIME returns the total amount of CPU usage
  • CMD returns the name of the control that launched the process.

You can choose to display a certain set of processes by using whatever combination of options (like -A -a, -C, -c, -d, -E, -e, -u, -X, -x, and others).

If you specify more than than one of these options, and so all processes which are matched by at least one of the given options will be displayed.

Screenshot-2021-06-28-at-3.55.10-PM
The ps command manual page.
Type man ps in your final to read the manual for the ps control, which has a complete reference for all options and their uses.

To brandish all running processes for all users on your auto, including their usernames, and to show processes not attached to your terminal, you tin utilise the command below:

                ps aux              

Hither'due south a breakup of the command:

  • ps: is the process status command.
  • a: displays information about other users' processes every bit well as your own.
  • u: displays the processes belonging to the specified usernames.
  • ten: includes processes that practice not have a decision-making final.
Screenshot-2021-06-28-at-4.39.05-PM

This will display the process for the electric current shell with 11 columns:

  • USER returns the username of the user running the process
  • PID returns the unique process ID
  • %CPU returns the percentage of CPU usage
  • %MEM returns the percent retentivity usage
  • VSV returns the virtual size in Kbytes
  • RSS returns the resident set size
  • TT returns the control last proper noun
  • STAT returns the symbolic procedure state
  • STARTED returns the fourth dimension started
  • CMD returns the command that launched the procedure.

How to Listing Running Processes in Linux using the peak and htop Commands

Yous can too use the top task manager control in Linux to see a real-time sorted list of superlative processes that apply the most memory or CPU.

Type top in your terminal and you'll become a result similar the one y'all encounter in the screenshot below:

Screenshot-2021-06-28-at-4.27.28-PM
You lot can type q to get out the session.

An culling to elevation is htop which provides an interactive organisation-monitor to view and manage processes. It likewise displays a existent-time sorted list of processes based on their CPU usage, and y'all can easily search, filter, and impale running processes.

htop is not installed on Linux past default, so you demand to install information technology using the command below or download the binaries for your preferred Linux distro.

                sudo apt update && sudo apt install htop              

Just blazon htop in your terminal and you lot'll get a consequence similar the one yous run across in the screenshot below:

Screenshot-2021-06-29-at-4.49.09-AM

How to Impale Running Processes in Linux

Killing a process ways that you terminate a running application or control. You tin can impale a process by running the kill command with the process ID or the pkill control with the process name like then:

                kill [PID]              

or

                pkill [COMMAND]              

To find the process ID of a running procedure, you tin apply the pgrep control followed by the name of the procedure like and so:

                pgrep iTerm2              

To kill the iTerm2 process in the screenshot above, we will employ any of the commands below. This volition automatically terminate and shut the iTerm2 process (awarding).

                kill 25781              

or

                kill iTerm2              

Conclusion

When you listing running processes, it is ordinarily a long and clustered list. You can pipe it through less to brandish the control output one page at a fourth dimension in your terminal like and then:

                ps aux | less              

or display only a specific procedure that matches a particular proper noun like and then:

                ps aux | grep Chrome              

I hope that yous now empathize what Linux processes are and how to manage them using the ps, top, and htop commands.

Make sure to check out the manual for each command by running homo ps, man summit, or man htop respectively. The manual includes a comprehensive reference you can check if you need any more assistance at whatsoever point.

Thanks for reading – thank you! 💙



Learn to lawmaking for gratis. freeCodeCamp's open source curriculum has helped more 40,000 people get jobs as developers. Get started

houghtherve.blogspot.com

Source: https://www.freecodecamp.org/news/linux-list-processes-how-to-check-running-processes/

0 Response to "Linux Check if Process Is Already Running if So Do Not Start Again"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel