Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Run (alternative to "command &")
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Sheri255
n00b
n00b


Joined: 15 Apr 2006
Posts: 29

PostPosted: Sat Jun 23, 2007 8:35 pm    Post subject: Run (alternative to "command &") Reply with quote

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
View user's profile Send private message
VincenzoVega
n00b
n00b


Joined: 15 Aug 2006
Posts: 42
Location: The land of mills and wooden shoes

PostPosted: Sat Jun 23, 2007 10:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
Syque
Tux's lil' helper
Tux's lil' helper


Joined: 15 Aug 2004
Posts: 110

PostPosted: Sun Jun 24, 2007 12:40 am    Post subject: Reply with quote

Also, "command & disown -h" will allow you to keep the application after you close the shell.
Back to top
View user's profile Send private message
Sheri255
n00b
n00b


Joined: 15 Apr 2006
Posts: 29

PostPosted: Sun Jun 24, 2007 10:54 am    Post subject: Reply with quote

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
View user's profile Send private message
synss
Apprentice
Apprentice


Joined: 08 Mar 2006
Posts: 282
Location: Dijon > Berlin > Tokyo > Nürnberg > München

PostPosted: Wed Sep 05, 2007 4:41 pm    Post subject: Reply with quote

Dralnu proposed dtach, here. It looks good but I had no time to try it today.
_________________
Compress portage tree
Elog viewer
Autodetect swap
Back to top
View user's profile Send private message
Voltago
Advocate
Advocate


Joined: 02 Sep 2003
Posts: 2561
Location: userland

PostPosted: Wed Sep 05, 2007 6:06 pm    Post subject: Reply with quote

Also, there is 'nohup' ('no hangup') from coreutils:
Code:
nohup xeyes &> /dev/null &
Back to top
View user's profile Send private message
ExZombie
Apprentice
Apprentice


Joined: 29 May 2004
Posts: 164

PostPosted: Wed Sep 05, 2007 8:06 pm    Post subject: Reply with quote

In ZSH, you can also use '&!' instead of '&' to imply disown.
Back to top
View user's profile Send private message
steveL
Advocate
Advocate


Joined: 13 Sep 2006
Posts: 3908
Location: The Peanut Gallery

PostPosted: Thu Sep 06, 2007 10:38 am    Post subject: Re: Run (alternative to "command &") Reply with quote

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
View user's profile Send private message
lolc
n00b
n00b


Joined: 15 May 2007
Posts: 4

PostPosted: Wed Sep 19, 2007 3:44 am    Post subject: Reply with quote

You can use "exit 0" to close the shell without closing any windows opened in it.
Back to top
View user's profile Send private message
steveL
Advocate
Advocate


Joined: 13 Sep 2006
Posts: 3908
Location: The Peanut Gallery

PostPosted: Wed Sep 19, 2007 10:11 am    Post subject: Reply with quote

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
View user's profile Send private message
lolc
n00b
n00b


Joined: 15 May 2007
Posts: 4

PostPosted: Wed Sep 19, 2007 10:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
Nate_S
Guru
Guru


Joined: 18 Mar 2004
Posts: 414

PostPosted: Sat Sep 22, 2007 5:37 pm    Post subject: Reply with quote

Similarly, closing the shell with Ctrl-D also leaves child processes open.
Back to top
View user's profile Send private message
steveL
Advocate
Advocate


Joined: 13 Sep 2006
Posts: 3908
Location: The Peanut Gallery

PostPosted: Sun Sep 23, 2007 3:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum