Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 11-17-2003, 02:22 AM   #1
Senior Member
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,225

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
execute command when program closes

how would i go about creating a shell script based 'launcher' menu that would respawn whenever the program launched quits? i would imagine such is possible considering how powerfull linux really is...
Old 11-17-2003, 02:25 PM   #2
Registered: Jul 2003
Location: Boston, MA, USA
Distribution: RedHat, SuSE, Gentoo, Slackware, Mandrake ...
Posts: 111

Rep: Reputation: 15
I'm not sure what you mean by "menu", but the basic way to respawn in a shell script is to write a function that loops running your program over and over. Start that function running in the background, and there you go. Here's a dumb example:

#! /bin/sh
respawn() {
while [ 1 ]
do "$@" </dev/null >/dev/null 2>&1
respawn sleep 5 &

I hope this is what you have in mind.
Old 11-17-2003, 04:05 PM   #3
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Re: execute command when program closes

Originally posted by frieza
Micro$oft 1> /dev/null 2> /dev/null
Not lazy enough :} ... too much typing!

Micro$oft > /dev/null 2>&1


Old 11-17-2003, 05:51 PM   #4
Registered: May 2001
Posts: 29,359
Blog Entries: 55

Rep: Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546
In the first place you should have told us which app or why it quits, there's usually lots of workarounds and alternatives, like if the app is a daemon, Google/see Freshmeat for "monit". Also see "man nohup".

Anyway, in your ~/.bashrc add this line:
restart() { "$@" && restart "$@"; }
start any app as usual, just prefix "restart".


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C program code to execute linux-command supermichou_fr Linux - Software 4 08-01-2012 08:25 AM
Execute a linux command using a java program tvalenzuela Programming 2 10-07-2005 11:59 AM
C function to execute a program and return the output of the program ryan.n Programming 4 08-14-2004 10:11 PM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM
ls command closes sftp connection SpecialK5106 Linux - Networking 4 11-03-2003 02:18 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration