﻿ Python: Show the individual process IDs involved - w3resource

# Python: Show the individual process IDs involved

## Python Basic - 1: Exercise-118 with Solution

In multiprocessing, processes are spawned by creating a Process object.
Write a Python program to show the individual process IDs (parent process, process ID etc.) involved.

Sample Solution:

Python Code:

``````from multiprocessing import Process
import os
def info(title):
print(title)
print('module name:', __name__)
print('parent process:', os.getppid())
print('process id:', os.getpid())
def f(name):
info('function f')
print('hello', name)
if __name__ == '__main__':
info('Main line')
p = Process(target=f, args=('bob',))
p.start()
p.join()
``````

Sample Output:

```Main line
module name: __main__
parent process: 23967
process id: 27986
function f
module name: __main__
parent process: 27986
process id: 27987
hello bob
```

Flowchart: Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

## Python: Tips of the Day

Returns the symmetric difference between two lists, after applying the provided function to each list element of both:

Example:

```def tips_symmetric_difference_by(p, q, fn):
_p, _q = set(map(fn, p)), set(map(fn, q))
return [item for item in p if fn(item) not in _q] + [item for item in q if fn(item) not in _p]
from math import floor
print(tips_symmetric_difference_by([4.2, 2.4], [4.6, 6.8],floor))
```

Output:

```[2.4, 6.8]
```

We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook