This preceding program should output the PIDs of both the main process and the created child process, as follows:
$ python3.6 01_identifyProcess.py
Main process PID: 85365
Child Process With PID: 85367
Child process terminating
This is just to quickly bring you up to speed with getting the process identifier for the current process. However, it's important to note that you can attain things other than the PID from your current process.
Much like your threading.Thread class, you can do things such as name your individual processes. Say you have two processes working on a certain type of tasks, and two other working on another distinct type of task. When logging the output of these tasks, you don't want to see a string of "process-1 did x", "process-2 did y".
Instead, you can name your child processes to be more meaningful--this only helps you further down the line when it comes to the fateful day that you have to debug a production issue, and find out exactly what went wrong.
To name a process after it has been created you can do something like this:
import multiprocessing
def myProcess():
print("{} Just performed X".format(multiprocessing.current_process().name))
def main():
childProcess = multiprocessing.Process(target=myProcess, name='My-Awesome-Process')
childProcess.start()
childProcess.join()
if __name__ == '__main__':
main()
This last code will output something like this:
$ python3.6 12_nameProcess.py
My-Awesome-Process Just performed X
Whenever it comes to writing production applications, do all you can to ensure traceability within your application. You will, more often than not, have to support the applications that you develop, so, ensure that you help your future self out by making logging as verbose as possible.