How to open multiple instances of a program in Lin

2019-06-28 02:52发布

Say for example, to open multiple instances of gedit editor I wrote a shell script like this-

gedit&
gedit&
gedit&
gedit&

But after I ran my shell script ./example.sh, I can find only one instance of gedit! I've even used the & operator, so that the shell doesn't wait for one instance to finish. Still I cannot see four instances of gedit.

Also I tried directly from the command prompt. If I just enter gedit& on the command line, it showed 1906 ( this is the PID of the newly created gedit process ), started one new gedit instance and returned to prompt again. When I typed gedit& on the command line, it showed 1909 this time, but no new instance of gedit! And I couldn't find any process with PID 1909 in the System Monitor too. Where did this new process go away?

Is the happening specific to gedit? If so, what is the generic behavior when creating multiple instances of a program?

5条回答
【Aperson】
2楼-- · 2019-06-28 03:33

Looks like gedit is first looking for a running instance and simply ignores further start-requests (just a wild guess). But the manual page says, that you can open another window:

--new-window
              Create a new toplevel window in an existing instance of gedit.

That wouldn't exactly solve your problem, but maybe that's what you were looking for in the first place.

Good luck, Alex.

查看更多
Viruses.
3楼-- · 2019-06-28 03:35

This seems specific to gedit, perhaps there's some option to turn off the check for a running instance.

查看更多
地球回转人心会变
4楼-- · 2019-06-28 03:47

It is specific to gedit. You are likely looking for gedit --new-window &.

From man gedit:

--new-window
       Create a new toplevel window in an existing instance of gedit.
查看更多
▲ chillily
5楼-- · 2019-06-28 03:49

Using this in a script. I've found that it does what I need it to:

#!/bin/bash
xterm -e "gedit; bash" &disown
查看更多
霸刀☆藐视天下
6楼-- · 2019-06-28 03:52

I came here, trying to start multiple instances of audacious.

Allowing only one instance is actually harder to implement, because the program needs to find and communicate with the instance already running. This is done via D-Bus. In order to prevent communication with the already started instance you can run the program in another D-Bus session:

nohup dbus-run-session audacious &
nohup dbus-run-session audacious &

Note: nohup will keep the program running even if the terminal is to be closed.

This method should also work for other programs which do not let the user choose between multiple instance vs. one instance.

Beware that this might introduce bugs, if multiple instances are accessing the same configuration files.

Tested with xfce 4.10.1 and dbus 1.8.16-1

For Scite:

scite -check.if.already.open=false &
查看更多
登录 后发表回答