How to check any script is running in linux using Python? Last Updated : 03 Mar, 2021 Comments Improve Suggest changes Like Article Like Report Python is a strong and exponentially growing programming language in the present day. There is a multiple-way to check which script is running in the background of a Linux environment. One of them is using the subprocess module in python. Subprocess is used to run new programs through Python code by creating new processes. In this article, we are going to see how to check any script is running in the background Linux using Python. Requirement : Python >=2.7, >= 3.0pip Installation of Subprocess : pip install subprocess.run We will use subprocess.checkout() methods to get all the running processes. Syntax : subprocess.check_output(args, *, stdin=None, stderr=None, shell=False, cwd=None, encoding=None, errors=None, universal_newlines=None, timeout=None, text=None, **other_popen_kwargs) This run command with argument and return output. stderr=subprocess.STDOUT is used to capture standard error in the result. Example 1 : In the below code we will get all the py script running in the background Linux Python3 import subprocess pytonProcess = subprocess.check_output("ps -ef | grep .py",shell=True).decode() pytonProcess = pytonProcess.split('\n') for process in pytonProcess: print(process) Output : Example 2 : In the below example we will check whether a particular script is running in background Python3 import subprocess pytonProcess = subprocess.check_output("ps -ef | grep test.py",shell=True).decode() pytonProcess = pytonProcess.split('\n') for process in pytonProcess: print(process) Output : Example 3 : In the below code we will get all the PHP script running in background Linux. Python3 import subprocess pytonProcess = subprocess.check_output("ps -ef | grep .php",shell=True).decode() PHPProcess = pytonProcess.split('\n') for process in PHPProcess: print(process) Output : Comment More infoAdvertise with us Next Article How to check any script is running in linux using Python? P pratapworkmail Follow Improve Article Tags : Python python-utility Practice Tags : python Similar Reads How to Run a Python Script using Docker? Docker helps you to run your Python application very smoothly in different environments without worrying about underlying platforms. Once you build an image using dockerfile you can run that image wherever you want to run. Docker image will help you to package all the dependencies required for the a 8 min read Run python script from anywhere in linux In Linux, there is a way to execute python files from anywhere. This can be done by typing several commands in the terminal. Prerequisite: Basic Shell Commands in Linux Basics of python Steps: At first, open the terminal and go to the home directory. To go the home directory type the following comma 2 min read How to check whether a script is running under Node.js or not ? In JavaScript, there is not any specific function or method to get the environment on which the script is running. But we can make some checks to identify whether a script is running on Node.js or in the browser. Using process class in Node.js: Each Node.js process has a set of built-in functionalit 3 min read How to run bash script in Python? If you are using any major operating system, you are indirectly interacting with bash. If you are running Ubuntu, Linux Mint, or any other Linux distribution, you are interacting with bash every time you use the terminal. Suppose you have written your bash script that needs to be invoked from python 2 min read How To Run Bash Script In Linux? Bash scripts, also called shell scripts, are programs that help automate tasks by storing a series of commands that often go together, like updates or upgrades. These scripts make it easier to perform tasks automatically instead of typing each command manually. After creating a Bash script, you can 6 min read How to Run Python Script in GitHub Actions ? A tool available on GitHub that can help you automate chores in your software projects is called GitHub Actions. It enables you to design workflows that, when executed automatically, carry out actions like as deploying, testing, and even sending out notifications. It basically works like a small rob 6 min read How to check Python Version : Windows, Linux and Mac Python has multiple versions, and it's important to know which version is installed on your system. This information is crucial because different Python versions may have variations in syntax or libraries, and ensuring you're using the correct version is vital for compatibility with your projects. I 5 min read How to Terminate a running process on Windows in Python? Process is a program that is being executed (processed). A process may not have to be one ran explicitly by the user, it could be a system process spawned by the operating system. Any applications that execute on an operating system firstly creates a process of its own to execute. In a typical os in 4 min read How to Run a Python Script Python scripts are Python code files saved with a .py extension. You can run these files on any device if it has Python installed on it. They are very versatile programs and can perform a variety of tasks like data analysis, web development, etc. You might get these Python scripts if you are a begin 6 min read How to Check the Syntax of a Bash Script Without Running It? A bash script is a text file that contains a sequence of commands that are executed by the bash shell, a Unix-based command-line interface. Bash scripts are used to automate tasks, create utility scripts, and perform a wide range of other functions in the command-line environment. They can include v 5 min read Like