A critical requirement for successful checkpoint/restore is ensuring that each process and thread is restored with its original Process ID (PID) and Thread ID (TID). Applications frequently rely on these IDs for inter-process communication, signal delivery, and as keys for shared resources (such as System V IPC).
CRIU employs two primary methods to request specific PIDs from the Linux kernel during restoration.
ns_last_pidOn older kernels, Linux does not provide a direct way to request a specific PID during a fork() or clone() call. Instead, CRIU uses the /proc/sys/kernel/ns_last_pid interface:
lock_last_pid) to minimize the chance of other processes interfering.N-1 to /proc/sys/kernel/ns_last_pid.fork().N.Limitations:
/proc filesystem and calling fork() is slow, especially for large process trees.clone3() with set_tidIntroduced in Linux kernel v5.5, the clone3() system call provides a much more robust and efficient mechanism via the set_tid array in the clone_args structure.
set_tid, allowing it to simultaneously set the process’s identity in all nested PID namespaces.CRIU includes architecture-specific assembly wrappers (RUN_CLONE3_RESTORE_FN) to safely execute these calls during the critical restoration phase.
clone3() and set_tid support during the Kerndat phase. If the modern interface is available, it is prioritized.