LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 06-18-2005, 05:58 AM   #1
jon_k
Member
 
Registered: Jul 2003
Location: Fort Worth, Texas
Distribution: Mepis Linux 2004
Posts: 547

Rep: Reputation: 30
How to create a bash script to automatically disown a process.


How can I create a bash script that will basically execute command&

And then automatically disown the process so it becomes seperate from under bash?

Is it possible?
 
Old 06-18-2005, 06:05 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

I can be wrong, but I think you are looking for the nohup command.

nohup <command> will run a command immune to hangups, with output to a non-tty.

Hope this helps.
 
Old 06-18-2005, 07:45 AM   #3
dr_zayus69
Member
 
Registered: Sep 2004
Location: western massachusetts
Distribution: fedora core 3, Suse 10
Posts: 877

Rep: Reputation: 35
just to make sure i understand is say you wanted to start firefox from the terminal by doing

firefox &

so that you don't get the output to the terminal and still have controll of the shell?

That would be a pretty easy script it would look like this

#!/bin/sh

#Start program with &
firefox &

exit 0

lets say you named that script webbrowswer just make sure the script is in a directory in your PATH variable (do echo $PATH to be sure) or make a link to your script in one then you could just type webbrowser and it would start up firefox like you typed firefox &. So just change firefox to whatever program you want to start up. I have no experience with nohup so druuna's method would probably work as well. If you still wanted a script with his method just change firefox & in mine to nohup firefox (or whatever program you end up using) hope this helps.
 
Old 06-18-2005, 09:19 PM   #4
jon_k
Member
 
Registered: Jul 2003
Location: Fort Worth, Texas
Distribution: Mepis Linux 2004
Posts: 547

Original Poster
Rep: Reputation: 30
Basically what I wanted this script for is so I could place this script in /usr/bin and use it to start a Windows program I use frequently. E.G. wine /path/to/exe

dr_zayus69: Tried your way since I've seen it done in init scripts, and it works exactly. Starts up the command I want, and then gives me my shell prompt back, and I can exit the shell too without the process dieing with it.

Here's thie script I wrote resulting from your advice, and it works.
Code:
#!/bin/bash

/home/jon_k/cxoffice/bin/wine /home/jon_k/.palace/palace32_original.exe &
exit 0
----------
Drunna's way works, and loads the program but it doesn't seem to give me control of my shell while the programs running. It seems to just log the output of stdout to nohup.out.

E.G.
Code:
jon_k@2[~]$ nohup xchat
nohup: appending output to `nohup.out'
at this point nothing else happens, until I hit ctrl-c or quit xchat
 
Old 06-19-2005, 05:42 AM   #5
dr_zayus69
Member
 
Registered: Sep 2004
Location: western massachusetts
Distribution: fedora core 3, Suse 10
Posts: 877

Rep: Reputation: 35
did you make a link to the script or put it in /usr/bin so you can just type it in and start it? If you want to do it via making a symbolic link i can help you out with that as well.
 
Old 06-19-2005, 05:53 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

@jon_k:

I thought (like I said before, I could be wrong ) that you wanted to detach the running script. The nohup option will not give you any control after the script is started (but you noticed that already).

Nohup is mostly used when you don't want/need/have a terminal after you start the script/program and cannot be used with interactive programs (like firefox, xchat etc).

Hope this clears things up a bit.
 
  


Reply


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
Can bash create a detached process? GN9500 Linux - Newbie 4 07-08-2012 07:28 PM
need help with a script to automatically create a subdirectory verbatim Linux - Newbie 6 04-26-2005 12:51 AM
automatically starting process in Fedora Core 2 by using script falkesgaard Programming 1 07-29-2004 10:11 AM
how do i kill a process from inside a bash script? mikaelo Programming 4 05-28-2004 08:51 AM
How to create a tiny script and make it start automatically tchigi Linux - Newbie 2 11-28-2003 03:48 AM


All times are GMT -5. The time now is 11:21 PM.

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