Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to call some application from script. I use an application which doesn't allow any parameters in CLI but I need to test it in two different monitors and screen resolutions so I have two different configuration files. To call needed version I use simple script (name it


rm /home/user/.app/config.ini
cp /home/user/.app/config.ini.1366x768 /home/user/.app/config.ini
sleep 1
/usr/local/bin/app &

or second version with cp line changed.

OK, it's simple. But when I quit this app (Ctrl+Q built-in function) it still runs. Calling ps command I see app and in processes list.

My question is: how should script be written to terminate/kill app and script totally? Something like this piece of code:

if [ "$1" = "start" ]; then /usr/bin/mplayer -fs -osdlevel 0 $2 ; fi
if [ "$1" = "stop" ]; then killall mplayer ; fi
share|improve this question

I offer you a simpler but uglier solution. :-)
You can kill a process after an amount of time with a package called timelimit:

sudo apt-get install timelimit

(on a terminal)

The -t option of timelimit is the number of seconds a process will stay alive: after that it will be killed (brutally) with the SIGKILL signal (if you did not specify other signals with the -S option).

timelimit OPTIONS command arguments

Edit: IF you want to use a "professional" solution, use trap:

trap 'kill $(jobs -p)' EXIT

It will execute the command in the commas after the "EXIT" signal.
To test it:trap "yes test" EXIT ... then use the exit command. Bye.

share|improve this answer
Thank you. 'Trap' command was exactly what I need but 'timelimit' is also interesting for other things. – stalker Oct 7 '13 at 21:17
I'm happy for you! ---> other questions are always welcome. ;-) – Lorenzo Ancora Oct 8 '13 at 15:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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