Beware of the spoiler after the asterisks below, if you want to think about the answer first.
A process that retrieves and handles a large volume of data from a database, while making millions of calls to `read' and `write', also calls `getpid' a few million times interspersed with the former: why?
The program is written in Python and runs on Linux.
Embarrassingly I couldn't figure that out (and I didn't want to spend a lot of time on that), so I asked LLM, to test it, too.
Its answer was quite satisfactory.
*
*
*
Answer (shortened):
A program or library that does or is prepared to do multiprocessing may need the pids of its processes or threads in order to manage mutual exclusion.
No comments:
Post a Comment