如何像 Chromium 那样克隆自己的实例?
当我在已经启动的情况下再次启动 chromium 时,我可以看到以下内容:
%> chromium 浏览器
在现有浏览器会话中创建新窗口。
C++ 中有没有通用的方法可以做类似的事情?或者它就像 C++ 中的“新”函数一样,只是克隆另一个对象?我很困惑。
When i launch chromium again when it's already started , i can see the following:
%> chromium-browser
Created new window in existing browser session.
Is there any general way in C++ to do a similar thing ? Or is it like just "new" function in C++ , simply clone another object ? I'm confused.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它与 C++ 中的“新”完全不同:它处于一个更高的水平。当新进程启动时,它会查找现有进程,如果找到,则会向其发送命令以创建新窗口,然后退出。该命令的语法和性质特定于应用程序(或应用程序框架),查找现有实例的机制也是如此。
It is nothing at all like "new" in C++: it's at a vastly higher level. When the new process is started, it looks for an existing process, and if it finds one, it sends it a command to create a new window, then exits. The syntax and nature of that command is specific to the application (or application framework), as is the mechanism by which an existing instance is found.
一种方法是使用 fork() 系统调用来创建与父进程相同的新进程。新进程将具有不同的进程 ID (PID)。对于 Chrome 浏览器,如果您查看任务管理器 (Windows) 或“ps”命令 (Linux) 的输出,您可以看到,一旦打开新选项卡,它就是一个具有新 PID 的新进程。
以下链接对于理解 fork()
http://www.yolinux.com/TUTORIALS/ ForkExecProcesses.html
One way could be to use fork() system call to create a new process identical to the parent process. The new process would have a different process id(PID). In the case of Chrome browser also, if you look at task manager (Windows) or the output of 'ps' command (Linux), you can see that once you open a new tab, it is a new process with new PID.
The following link would be useful for understanding fork()
http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html