I have a certain Python script that I want to know what the current PID is through the script itself.
How can I do this?
Through this too, can I determine that it runs only once?
I have a certain Python script that I want to know what the current PID is through the script itself.
How can I do this?
Through this too, can I determine that it runs only once?
Before answering, talk a little about PID .
Process identifier, PID or even process ID is a unique number that is assigned by the operating system when a process is executed. This number is used to reference a process you are running.
source: wikipedia
In short, every process running on the operating system will have its own PID .
There are a few ways to do this, but the simplest thing is to just import the os
and use the getpid()
to get the PID of the current process.
Example:
import os
pid = os.getpid()
You can also get the PID based on the process name, and other forms.