View previous topic :: View next topic |
Author |
Message |
Sheri255 n00b
Joined: 15 Apr 2006 Posts: 29
|
Posted: Sat Jun 23, 2007 8:35 pm Post subject: Run (alternative to "command &") |
|
|
There was one program I missed for a very long time. A program that could execute programs so that they weren't attached to the shell that executed them. I always closed those windows and lost the running application. I found the "command &" method quite buggy, so when i heard of the fork() command, I created a simple program for it. Feel free to use it, feel free to improve it, feel free to ignore it.
Code: | #include <iostream>
int main(int argv, char** argc)
{
if (argv < 2)
{
std::cout << "Usage: " << argc[0] << " \"command\" [\"command 2\" ...]" << std::endl;
return 1;
}
for (unsigned int i = 1; i < argv; ++i)
{
if (fork())
std::cout << "Executing " << argc[i] << "..." << std::endl;
else
return system(argc[i]);
}
return 0;
} |
I use it daily, and I hope others will have use for it to. |
|
Back to top |
|
|
VincenzoVega n00b
Joined: 15 Aug 2006 Posts: 42 Location: The land of mills and wooden shoes
|
Posted: Sat Jun 23, 2007 10:45 pm Post subject: |
|
|
Tried screen yet ? It's the best thing since sliced bread. It makes apps detachable, multiplexes (up to 10 virtual terminals) etc. |
|
Back to top |
|
|
Syque Tux's lil' helper
Joined: 15 Aug 2004 Posts: 110
|
Posted: Sun Jun 24, 2007 12:40 am Post subject: |
|
|
Also, "command & disown -h" will allow you to keep the application after you close the shell. |
|
Back to top |
|
|
Sheri255 n00b
Joined: 15 Apr 2006 Posts: 29
|
Posted: Sun Jun 24, 2007 10:54 am Post subject: |
|
|
VincenzoVega wrote: | Tried screen yet ? It's the best thing since sliced bread. It makes apps detachable, multiplexes (up to 10 virtual terminals) etc. | Yeah, I use screen, but when I start my computer i usually run "run amsn skype" etc. I don't want to assign a screen for that, I just want it to run...
Syque wrote: | Also, "command & disown -h" will allow you to keep the application after you close the shell. | I didn't know of that one, seems useful, but not as fast as the "run command"... |
|
Back to top |
|
|
synss Apprentice
Joined: 08 Mar 2006 Posts: 282 Location: Dijon > Berlin > Tokyo > Nürnberg > München
|
|
Back to top |
|
|
Voltago Advocate
Joined: 02 Sep 2003 Posts: 2593 Location: userland
|
Posted: Wed Sep 05, 2007 6:06 pm Post subject: |
|
|
Also, there is 'nohup' ('no hangup') from coreutils:
Code: | nohup xeyes &> /dev/null & |
|
|
Back to top |
|
|
ExZombie Apprentice
Joined: 29 May 2004 Posts: 170
|
Posted: Wed Sep 05, 2007 8:06 pm Post subject: |
|
|
In ZSH, you can also use '&!' instead of '&' to imply disown. |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Thu Sep 06, 2007 10:38 am Post subject: Re: Run (alternative to "command &") |
|
|
Sheri255 wrote: | A program that could execute programs so that they weren't attached to the shell that executed them. I always closed those windows and lost the running application. I found the "command &" method quite buggy, so when i heard of the fork() command, I created a simple program for it. Feel free to use it, feel free to improve it, feel free to ignore it. ;) |
It's really nice to see some code on here, so thanks for that. But yeah, man nohup, disown or screen; if you're not sure of what to use for something, come and ask in #bash or #friendly-coders on irc.freenode.org. (#bash are a bit grumpy;)
Quote: | I use it daily, and I hope others will have use for it to. :) |
dtach is more for your own programs. Now if only you used C.. ;P |
|
Back to top |
|
|
lolc n00b
Joined: 15 May 2007 Posts: 4
|
Posted: Wed Sep 19, 2007 3:44 am Post subject: |
|
|
You can use "exit 0" to close the shell without closing any windows opened in it. |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Wed Sep 19, 2007 10:11 am Post subject: |
|
|
lolc wrote: | You can use "exit 0" to close the shell without closing any windows opened in it. |
I think that would mean any apps that aren't disown'ed/nohup'ed would close. |
|
Back to top |
|
|
lolc n00b
Joined: 15 May 2007 Posts: 4
|
Posted: Wed Sep 19, 2007 10:40 pm Post subject: |
|
|
steveL wrote: | lolc wrote: | You can use "exit 0" to close the shell without closing any windows opened in it. |
I think that would mean any apps that aren't disown'ed/nohup'ed would close. |
I tried this in Debian.
$ gcalctool &
$ exit
gcalctool is closed.
$ gcalctool &
$ exit 0
gcalctool is not closed. |
|
Back to top |
|
|
Nate_S Guru
Joined: 18 Mar 2004 Posts: 414
|
Posted: Sat Sep 22, 2007 5:37 pm Post subject: |
|
|
Similarly, closing the shell with Ctrl-D also leaves child processes open. |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Sun Sep 23, 2007 3:25 pm Post subject: |
|
|
You're right lolc! Wow, never knew that, very handy. CTRL-D works too as you said, Nate_S. (I tested with kwrite file &) Thank you, both :-) |
|
Back to top |
|
|
|