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 Like