How to set process ID in Linux for a specific program

后端 未结 6 918
后悔当初
后悔当初 2020-12-03 01:15

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.

6条回答
  •  無奈伤痛
    2020-12-03 02:11

    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.

提交回复
热议问题