Reputation: 28535
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?
Upvotes: 7
Views: 20760
Reputation: 2131
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.14.1 and dbus 1.12.20
For Scite:
scite -check.if.already.open=false &
A word of caution:
If you, like me, have your system running for multiple months and have edited some of your shortcuts or aliases to open with this hack, then after a while some programs will not start anymore because there are already too many open D-Bus session. In this case you have to kill the started D-Bus sessions, which do not close when the started program closes. The other way around, killing the D-Bus session, will also kill the opened program, so use with care! For me personally, I have some long running autostarted programs which I want to keep open (firefox), so I kill all but the first 10 D-Bus sessions with this:
for pid in $( ps --sort start_time -aux | grep dbus-daemon | tail +10 | awk '{ print $2; }' ); do kill $pid; done
The cleanest solution would be to write a launcher script which waits for the program to finish and then closes the opened D-Bus sessions. But this is a bit more difficult than it seems because it is hard to find the PID of the corresponding D-Bus session.
P.S.: I also used this hack because there seems to be some program on my system which, after a while, slows down the system's default file open dialog to take multiple minutes if not longer to open! Programs then seem to hang when trying to save or open files. A new D-Bus sessions seems to fix this for some reason. While writing this, I found that pkill gvfsd-trash
also works and that it may have been this bug. So until this gets shipped, I guess I'll add pkill gvfsd-trash
to my crontab.
Upvotes: 7
Reputation: 65
Using this in a script. I've found that it does what I need it to:
#!/bin/bash
xterm -e "gedit; bash" &disown
Upvotes: 1
Reputation: 1614
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.
Upvotes: 1
Reputation: 5536
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.
Upvotes: 5
Reputation: 9549
This seems specific to gedit, perhaps there's some option to turn off the check for a running instance.
Upvotes: 3