You can go quickly to the question starting reading from 'Having said that'
The following are details on my specific needs

I'm on lubuntu oneiric and trying to create a desktop launcher to start / stop tomcat. I'm experiencing problems which are explained in this thread I opened yesterday on lxde forum.

Basically the desktop launcher, which just executes the command
inside a lxterminal window works, but if I close the lxterminal window opened by the launcher and which executed the command .. then tomcat is just shut down.

I would like instead to close that window while having tomcat keeping running of course.
The window needs just to execute the command to start it and nothing else.

Searching inside the whoooole code run by the above command I finally found that the guilty is the following code:

/opt/jdk1.6.0_22/bin/java  \
-Dsolr.solr.home=/home/foo/solr/solr_config/current/master/ \
-Dsolr.data.dir=/home/foo/solr/data \
-Dsolr.solr.home=/home/foo/solr/solr_config/current/master/ \
-Dsolr.data.dir=/home/foo/solr/data \
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
-Djava.util.logging.config.file=/usr/local/tomcat6/conf/logging.properties \
-Djava.endorsed.dirs="/endorsed" \
-classpath ":/usr/local/tomcat6/bin/bootstrap.jar:/usr/local/tomcat6/bin/commons-logging-api.jar" \
-Dcatalina.base="/usr/local/tomcat6" \
-Dcatalina.home="/usr/local/tomcat6" \
-Djava.io.tmpdir="/usr/local/tomcat6/temp" \
org.apache.catalina.startup.Bootstrap "" start \
>> "/usr/local/tomcat6"/logs/catalina.out 2>&1 &

In fact if I run this command inside a new lxterminal window, the same behavior is noticed:
A) tomcat starts: if I open a new lxterminal and type:

$ ps aux | grep tomcat
foo     21492  0.4  1.5 934436 47248 pts/2    Sl   11:37   0:03 /opt/jdk1.6.0_22/bin/java -Dsolr.solr.home=/home/foo/solr/solr_config/current/master/ -Dsolr.data.dir=/home/foo/solr/data -Dsolr.solr.home=/home/foo/solr/solr_config/current/master/ -Dsolr.data.dir=/home/foo/solr/data -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/usr/local/tomcat6/conf/logging.properties -Djava.endorsed.dirs=/endorsed -classpath :/usr/local/tomcat6/bin/bootstrap.jar:/usr/local/tomcat6/bin/commons-logging-api.jar -Dcatalina.base=/usr/local/tomcat6 -Dcatalina.home=/usr/local/tomcat6 -Djava.io.tmpdir=/usr/local/tomcat6/temp org.apache.catalina.startup.Bootstrap  start
foo     21666  0.0  0.0   4476   768 pts/4    S+   11:53   0:00 grep --color=auto tomcat

B) if I close the first lxterminal window (the one in which I ran the long command above) then tomcat shuts down as well. If, from the second lxterminal window, I type again

$ ps aux | grep tomcat
foo     21694  0.0  0.0   4476   772 pts/4    S+   11:57   0:00 grep --color=auto tomcat

Having said that
the above looong command is just a background job: if I open a lxterminal and simply type

$ top &
[1] 21921

and, while keeping this window opened, I open a second lxterminal window and type

$ ps aux | grep top
foo     21921  0.0  0.0   2452   764 pts/2    T    12:07   0:00 top
foo     21927  0.0  0.0   4476   772 pts/4    S+   12:08   0:00 grep --color=auto top

I can see 'top' running, while if I close the first window and then from the second one type again

$ ps aux | grep top
foo     21927  0.0  0.0   4476   772 pts/4    S+   12:08   0:00 grep --color=auto top

the 'top' command is shut down as well.

So is there a way to start a job from a lxterminal window and have this job still running even after closing the lxterminal window which fired it?

To be clear:
I want to open a lxterminal window which executes a command (like top &), close this lxterminal window and still have the executed command running.

For those who read my details on the top page:
the strange is that if I open a lxterminal window, directly type
and then close that window .. then tomcat still runs. Not from the desktop launcher which simply opens an lxterminal window and fire the same command and then it closes!

  • 3
    You probably want nohup or screen, depending on whether the process is interactive and you need to get back to it. – David Schwartz Mar 28 '12 at 10:24
  • 1
    If you run exit or press CTRL+D instead of just closing the window, the job will stay running (if backgrounded via &). – Patrick Mar 28 '12 at 12:23

A simple solution is use screen You may need to install it by

apt-get install screen

Then you can use

screen your_command_here

You can use Ctrl-AD to quit screen but keep it running in background. Then you can use

screen -r 

to go back to that screen window.

| improve this answer | |

In bash, you can say:

my_program &
disown -h %1


| improve this answer | |

I think your (Tomcat-) processes are killed when the terminal window is closed because the shell, running in the terminal window, is the parent process of your Tomcat process. so when a parent gets killed, all child processes are killed too.

If you don't want this to happen you could try launching your process like this:

nohup /usr/local/tomcat6/bin/startup.sh

| improve this answer | |
  • A process's children arent killed when a parent dies. Only when an interactive shell exits, it will send a SIGHUP to all jobs running under that shell. – Patrick Mar 28 '12 at 12:23
  • @Patrick Thank you for your tips! The problem was that I used interactive shells too .. see my edited for the solution. – Luca Borrione Mar 28 '12 at 12:49


Thanks to your answers I finally solved it: the problem was also that I used interactive shell see this other question of mine.
So the solution was:

A) Put in .profile too what tomcat needs

export PATH=/opt/jdk1.6.0_22/bin:$PATH
export JAVA_HOME=/opt/jdk1.6.0_22
export JRE_HOME=/opt/jdk1.6.0_22
export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=/home/foo/solr/solr_config/current/master/ -Dsolr.data.dir=/home/foo/solr/data"

B) Remove any interactive shell and added nohup and exit:
so my desktop launcher has

[Desktop Entry]
Exec=lxterminal --command "bash '/home/foo/scripts/Tomcat/tomcat-startup.sh'"

while tomcat-startup.sh basically does:

nohup bash "/usr/local/tomcat6/bin/startup.sh"

And everything just works fine! :D

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.