I was wondering if there is some way to force to use some specific process ID to Linux to some application before running it. I need to know in advance the process ID.
You could just repeatedly call fork()
to create new child processes until you get a child with the desired PID. Remember to call wait()
often, or you will hit the per-user process limit quickly.
This method assumes that the OS assigns new PIDs sequentially, which appears to be the case eg. on Linux 3.3.
The advantage over the ns_last_pid
method is that it doesn't require root permissions.