2
I have a certain Python script that I want to know what is the current PID of it, through the script itself.
How can I do that?
Through this too, I can determine that it be executed only once?
2
I have a certain Python script that I want to know what is the current PID of it, through the script itself.
How can I do that?
Through this too, I can determine that it be executed only once?
4
Before we answer, let’s talk a little about PID.
Process Identifier (process identifier), PID, or process ID is a unique number that is assigned by the operating system when a process is executed. This number is used to refer to a process that is running.
source: wikipedia
In short, each process run on the operating system will have its own PID.
There are some ways to do this, but the simplest is just to import the os
and use the method getpid()
to obtain the PID of the current process.
Example:
import os
pid = os.getpid()
You can also get the PID based on the name of the case, and other forms.
Browser other questions tagged python process
You are not signed in. Login or sign up in order to post.
You want the script itself to return your PID or the script to return the PID of another script?
– Randrade
"Currently running". the script itself, I will edit :p
– Wallace Maxters