You are not logged in.

#1 2009-09-16 19:40:48

daneel971
Member
Registered: 2008-03-28
Posts: 197

[OPENBOX] programs run from a terminal exit when terminal closes

Using KDE, I can open konsole, type something like "kwrite &", close konsole and working happily with kwrite.
The same doesn't work with openbox: when i run a program from a terminal  - with the final "&", of course - if I close the terminal the program exits.
Does someone have a clue?

Offline

#2 2009-09-16 20:36:42

hrobeers
Member
From: Belgium
Registered: 2008-11-05
Posts: 79

Re: [OPENBOX] programs run from a terminal exit when terminal closes

try executing "bg" after you did "kwrite &"
bg sends it to the background, I believe you can close the terminal afterwards.

Offline

#3 2009-09-17 03:56:10

axion419
Member
Registered: 2007-04-12
Posts: 185

Re: [OPENBOX] programs run from a terminal exit when terminal closes

I have always ran things like this and it will close the terminal.

'application & exit'

Offline

#4 2009-09-17 04:02:19

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: [OPENBOX] programs run from a terminal exit when terminal closes

Why not use something like gmrun and give it a keybinding? There's little point to opening a terminal, only to background a graphical application and then closing the terminal.

It seems to depend on the app whether it gets killed or not after you close the terminal.

@ hrobeers: & tells bash to background the app, bg is only needed for an app that's already running (and not backgrounded).


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#5 2009-09-17 04:23:20

axion419
Member
Registered: 2007-04-12
Posts: 185

Re: [OPENBOX] programs run from a terminal exit when terminal closes

B wrote:

Why not use something like gmrun and give it a keybinding? There's little point to opening a terminal, only to background a graphical application and then closing the terminal.

In that vien, I always liked http://bbs.archlinux.org/viewtopic.php?id=56283 or even better, dmenu.

Offline

#6 2009-09-17 04:55:07

daneel971
Member
Registered: 2008-03-28
Posts: 197

Re: [OPENBOX] programs run from a terminal exit when terminal closes

Thanks all for your answers - I'll do some other test tonight.

B wrote:

Why not use something like gmrun and give it a keybinding? There's little point to opening a terminal, only to background a graphical application and then closing the terminal.

I agree: anyway, it should work but it's not working - that's what bugs me.
Most important, it works perfectly in KDE but not in Openbox - so I'm curious to know why.

It seems to depend on the app whether it gets killed or not after you close the terminal.

It seem that the issue arises with different terminals (konsole, terminator, xterm) and every apps I run from them (not only KDE apps).

Last edited by daneel971 (2009-09-17 04:55:22)

Offline

#7 2009-09-17 09:15:18

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: [OPENBOX] programs run from a terminal exit when terminal closes

Interesting, maybe konsole forks a process ?


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#8 2009-09-17 09:16:10

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: [OPENBOX] programs run from a terminal exit when terminal closes

Try

application > /dev/null 2>&1 &

Or use the much more comfortable way B told you, gmrun is really nice!

Offline

#9 2009-09-17 09:41:41

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: [OPENBOX] programs run from a terminal exit when terminal closes

bashrun/gmrun automatically keep the running process in the background, whereas starting from the console usually only forks.
Personally I prefer bashrun over gmrun. It has less dependencies.
OTH gmrun looks nicer.
Just a matter of taste.


To know or not to know ...
... the questions remain forever.

Offline

#10 2009-09-17 11:59:42

Knute
Member
From: Minot, ND
Registered: 2009-03-17
Posts: 604

Re: [OPENBOX] programs run from a terminal exit when terminal closes

The bash command that you are looking for is disown.
If you disown the jobspec then SIGHUP won't be sent to it when the shell closes.


Knute

Offline

#11 2009-09-17 18:04:00

daneel971
Member
Registered: 2008-03-28
Posts: 197

Re: [OPENBOX] programs run from a terminal exit when terminal closes

Army's suggestion doesn't work. Both nohup and disown work.
The question is: how come that in KDE I don't need anything special in order to launch a program from a terminal (with the final "&", of course) and then close the terminal, while in Openbox I need to explicit use nohup or disown?
BTW: I checked in openbox with shopt and I can confirm that huponexit is off.

Offline

#12 2009-09-17 23:04:27

Knute
Member
From: Minot, ND
Registered: 2009-03-17
Posts: 604

Re: [OPENBOX] programs run from a terminal exit when terminal closes

Well, are you using the same terminal in both environments?


Knute

Offline

#13 2009-09-18 05:16:25

daneel971
Member
Registered: 2008-03-28
Posts: 197

Re: [OPENBOX] programs run from a terminal exit when terminal closes

Knute wrote:

Well, are you using the same terminal in both environments?

Sure. In both environment I tried with Konsole and Terminator. Only in Openbox I tried even with Xterm.
The terminal (terminator and xterm) works as expected with Crunchbang (installable live-cd with openbox desktop): I took a look at various config files in Crunchbang, but I didn't notice anything "strange".

Offline

#14 2009-09-18 05:38:05

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: [OPENBOX] programs run from a terminal exit when terminal closes

Trying to learn more about this behaviour:
It is the way an interactive bash shell works. To quote from man bash:

...
       The shell exits by default upon receipt of a SIGHUP.   Before  exiting,
       an  interactive  shell  resends  the  SIGHUP  to  all  jobs, running or
       stopped.  Stopped jobs are sent SIGCONT to ensure that they receive the
       SIGHUP.   To  prevent the shell from sending the signal to a particular
       job, it should be removed from the jobs table with the  disown  builtin
       (see  SHELL  BUILTIN  COMMANDS  below)  or marked to not receive SIGHUP
       using disown -h.
...
       disown [-ar] [-h] [jobspec ...]
              Without options, each jobspec  is  removed  from  the  table  of
              active  jobs.   If jobspec is not present, and neither -a nor -r
              is supplied, the shell's notion of the current job is used.   If
              the -h option is given, each jobspec is not removed from the ta‐
              ble, but is marked so that SIGHUP is not sent to the job if  the
              shell  receives a SIGHUP.  If no jobspec is present, and neither
              the -a nor the -r option is supplied, the current job  is  used.
              If no jobspec is supplied, the -a option means to remove or mark
              all jobs; the -r option without  a  jobspec  argument  restricts
              operation  to running jobs.  The return value is 0 unless a job‐
              spec does not specify a valid job.

It looks like KDE disowns background processes by default. (Someone has to proof this, however.)

There are applications which obviously disown themselves, even in openbox, like e.g. conky & (if run from urxvt).

BTW: It is informative to follow this behaviour in htop.


To know or not to know ...
... the questions remain forever.

Offline

#15 2009-09-18 10:26:18

dobedo
Member
From: Belgium
Registered: 2008-10-04
Posts: 113

Re: [OPENBOX] programs run from a terminal exit when terminal closes

Another trick: if you put your command between parentheses, then the process will be child of init (process id 1) i.o. of the runnning shell

(kwrite &)

When you will close the terminal, the runnning job will then not been killed.

Remark: I'm far from being a linux expert so feel free to comment on this if you see problems with that way of doing things...

Offline

#16 2009-09-18 11:55:47

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: [OPENBOX] programs run from a terminal exit when terminal closes

dobedo wrote:

Another trick: if you put your command between parentheses, then the process will be child of init (process id 1) i.o. of the runnning shell

(kwrite &)

When you will close the terminal, the runnning job will then not been killed.

Great. This is something I really missed.
In order to really understand what happens. Is this caused by this behaviour (quoted from man bash)?

COMMAND EXECUTION ENVIRONMENT
...
       Command substitution, commands grouped with parentheses, and asynchronous com‐
       mands are invoked in a subshell environment that is a duplicate of  the  shell
       environment,  except  that  traps  caught by the shell are reset to the values
       that the shell inherited from its parent at invocation
.  Builtin commands that
       are invoked as part of a pipeline are also executed in a subshell environment.
       Changes made to the subshell environment cannot affect the  shell's  execution
       environment.

Or is there another mechanism at work?

(Learning bash for half a century now. And still not grasped some very basics... roll )

Edit:
Oops! I am not that old. Certainly it is (more than) half a decade only.
hmm

Last edited by bernarcher (2009-09-18 19:18:16)


To know or not to know ...
... the questions remain forever.

Offline

#17 2009-09-18 17:36:13

dobedo
Member
From: Belgium
Registered: 2008-10-04
Posts: 113

Re: [OPENBOX] programs run from a terminal exit when terminal closes

bernarcher wrote:

In order to really understand what happens. Is this caused by this behaviour (quoted from man bash)?

Yep, it's indeed the subshell stuff.
Cheers.

Offline

Board footer

Powered by FluxBB