PID Pollution by launching process [closed]

2019-08-18 22:31发布

On nix/mac if i launch a process with nsiProcess run or runAsync, the launching process PID gets onto the files (like locked files) etc of the launching process.

This gif shows i have one profile. I do lsof on the parentlock file, it shows one pid. I then launch a second profile, it now shows that one of the parentlock files now has multiple pid. Any ideas on how to avoid this pid pollution? via nsiprocess or jsctypes/libc methods I can use?

Oh here's the gif showing my screencast, it loops once, so if u want to repeat just a simply page refresh

http://i.imgur.com/OsuGbqB.gif

1条回答
放荡不羁爱自由
2楼-- · 2019-08-18 22:45

Under unix spawning a new process is generally done by first fork()ing the parent process and then replacing the child with a new process image in place through exec().

Forking causes the new process to inherit - among many other things - all file descriptors from the parent process. It may then shed some of them on calling exec(), but does not do so by default. See this SO answer how to mark file descriptors for close-on-exec.

  • If you have control over the spawned process you can just find the descriptor in question and close it.
  • If you do not, then you have to write an executable which marks the descriptor for close-on-exec (see above) and then invoke exec() to finally start the child process you actually wanted.
    • Edit: as pointed out in the comments, there are existing programs that do just that
查看更多
登录 后发表回答