Influence which PID will be the next
To restore a checkpointed process with CRIU the process ID (PID) has to be the same it was during checkpointing. CRIU uses /proc/sys/kernel/ns_last_pid to set the PID to one lower as the process to be restored just before fork()
-ing into the new process.
The same interface (/proc/sys/kernel/ns_last_pid
) can also be used from the command-line to influence which PID the kernel will use for the next process.
# cat /proc/sys/kernel/ns_last_pid 1626 # echo -n 9999 > /proc/sys/kernel/ns_last_pid # cat /proc/sys/kernel/ns_last_pid 10000
Writing ‘9999’ (without a ‘new line’) to /proc/sys/kernel/ns_last_pid
tells the kernel, that the next PID should be ‘10000’. This only works if between after writing to /proc/sys/kernel/ns_last_pid
and forking the new process no other process has been created. So it is not possible to guarantee which PID the new process will get but it can be influenced.
There is also a posting which describes how to do the same with C: How to set PID using ns_last_pid