Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get process ID with python

How to get the current process id with python on windows?

there are this function os.geteuid() but its only works with linux/unix could someone tell what it the pythonic way to get the current process id on windows.

like image 257
AKM Avatar asked Oct 04 '10 08:10

AKM


People also ask

What is OS Getpid ()?

os. getpid () Return the current process id. os. getppid ()

What does process () do in python?

In Python, a process is an instance of the Python interpreter that executes Python code. In Python, the first process created when we run our program is called the MainProcess. It is also a parent process and may be called the main parent process. The main process will create the first child process or processes.

How do I know if a process is running on PID?

The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.


1 Answers

Do you really want the process ID? Then the answer is this:

>>> import os
>>> os.getpid()
5328

on either Windows or Unix (documentation of os.getpid).

os.geteuid() doesn't get the process ID, which makes me wonder whether you're really asking a different question...?

like image 170
RichieHindle Avatar answered Oct 04 '22 04:10

RichieHindle