发射过程中的PID污染 [英] PID Pollution by launching process

查看:375
本文介绍了发射过程中的PID污染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在nix / mac上,如果我用nsiProcess run或runAsync启动一个进程,启动进程的PID将进入启动进程的文件(如锁定文件)等。

<这个gif显示我有一个配置文件。我在文件上做了lsof,它显示了一个pid。然后,我启动第二个配置文件,现在显示其中一个parentlock文件现在有多个pid。任何想法如何避免这种污染?通过nsiprocess或jsctypes / libc方法,我可以使用?



哦,这是gif显示我的screencast,它循环一次,所以如果你想重复只是一个简单的页面刷新



进入父进程,然后用新的进程映像替换子进程 / em>通过 exec()

分叉会导致新进程继承父进程中的所有文件描述符。然后它可能在调用 exec()时释放其中的一些,但默认情况下不会这样做。请参阅这个答案如何标记文件描述符,
$ b


  • 如果你能控制产生的进程,你可以找到有问题的描述符并关闭它。

  • 如果你不这样做,那么你必须编写一个可执行文件来标记close-on-exec描述符(见上),然后调用 exec()

    • 编辑:正如在评论中指出的那样,现有的程序仅仅是这样做的



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

解决方案

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

这篇关于发射过程中的PID污染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆