Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Xterm &
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
paradigm-X
Apprentice
Apprentice


Joined: 19 Sep 2013
Posts: 168

PostPosted: Sat Feb 01, 2014 6:15 pm    Post subject: Xterm & Reply with quote

When I use this command in xterm, some_command &, a new window opens with a program corresponding to the command, and it seems to be altogether separate window from the xterm window from which it was spawned. However, when I do this command in xterm, some_command, without the "&" after it, then a window opens likewise, but it seems to be connected to the original xterm window. I can kill the spawned window with Ctl+c in the xterm window.

Where can I find a discussion of this connection between these windows? I am interested in knowing, among other things, whether this connection servers any purpose other than allowing me to kill the second process? In other words, can I use the connection for any other use? I would appreciate any pointers someone can provide to a link or other discussion concerning this matter. Thanks.
Back to top
View user's profile Send private message
gotyaoi
Tux's lil' helper
Tux's lil' helper


Joined: 01 Apr 2013
Posts: 92

PostPosted: Sun Feb 02, 2014 1:10 am    Post subject: Reply with quote

The & means run the command in the background. Normally, without the &, a program open in the foreground of the shell that called it, preventing another program from being run from that shell. With the &, the program opens in the background, allowing the shell to do other things while the program runs.

This is of varying levels of utility, for example X programs don't generally require the use of the terminal, so doing other things with the terminal might be nice. It's also useful for processes that run a server, and don't necessarily need interaction from a user after starting. On the other hand, using & with a CLI program that requires user interaction would probably make things more difficult.

You may notice that when using &, the shell prints a number, this is the process ID of the backgrounded command, which can be passed to the 'kill' command to kill the process, much like Ctrl+C when the process is running in the foreground. You can also issue the 'jobs' command to list all the programs you have backgrounded or suspended.
Back to top
View user's profile Send private message
666threesixes666
Veteran
Veteran


Joined: 31 May 2011
Posts: 1235
Location: 42.68n 85.41w

PostPosted: Sun Feb 02, 2014 1:20 am    Post subject: Reply with quote

its not really running in the background if the shell cant be closed from my view point. i use alt + f2 for commands i want in the background. this has bothered me for years...
_________________
cat /etc/*-release
Funtoo Linux - baselayout 2.2.0
consider this warning no. 1
https://wiki.gentoo.org/index.php?title=Special:Contributions/666threesixes666&offset=&limit=500&target=666threesixes666
Back to top
View user's profile Send private message
Chiitoo
l33t
l33t


Joined: 28 Feb 2010
Posts: 831
Location: Here and Away Again

PostPosted: Sun Feb 02, 2014 1:22 am    Post subject: Reply with quote

666threesixes666 wrote:
its not really running in the background if the shell cant be closed from my view point.

It can be, as far as I can tell.

I often run apps that way, and I can indeed close the terminal application (e.g., konsole), and the app will keep on running until terminated.

Apologies if I misunderstood what you meant. ^^
_________________
Kind Regards,
~ The Noob Unlimited ~

Sore wa sore, kore wa kore.
Back to top
View user's profile Send private message
paradigm-X
Apprentice
Apprentice


Joined: 19 Sep 2013
Posts: 168

PostPosted: Sun Feb 02, 2014 9:00 pm    Post subject: Reply with quote

> "You may notice that when using &, the shell prints a number, this is the process ID of the backgrounded command, which can be passed to the 'kill' command to kill the process, much like Ctrl+C when the process is running in the foreground. "

that number is handy in case of problems with the running process because I have seen a number of times when it was hard to identify easily exactly which process was associated with any given number, and that made it somewhat of a guess in 'top'. Thanks for your reply and take care.
Back to top
View user's profile Send private message
i92guboj
Moderator
Moderator


Joined: 30 Nov 2004
Posts: 9804
Location: Córdoba (Spain)

PostPosted: Mon Feb 03, 2014 4:16 pm    Post subject: Reply with quote

Job control and process management in *nix could easily fill up any modern library alone.

You could start here:
http://www.tutorialspoint.com/unix/unix-processes.htm

Then, here, which explains some bash specific stuff (bash is probably your shell if you haven't chosen another on purpose):
http://web.mit.edu/gnu/doc/html/features_5.html

Once you know a bit about the background come back and ask again. You'll probably be more accurate on your question and we will be able to provide you with a better answer as well :)
_________________
Gentoo Handbook | My website
Back to top
View user's profile Send private message
luismw
Tux's lil' helper
Tux's lil' helper


Joined: 04 Jan 2010
Posts: 85

PostPosted: Tue Feb 04, 2014 9:43 am    Post subject: Reply with quote

The shell can be thought of a program you can use to launch other programs. Unless you tell it otherwise, it will assume that you want to run a program, interact with it, and control won't return to the shell until that program ends. This is a logical choice for most terminal programs, such as nano.

As you already know, you can use & to run in the background, which is more appropriate for X programs. If you forgot the &, you can also press ctrl+Z to stop the program and then bg to tell the shell to resume running, but now in the background.

Since it was the shell the process that launched your application, if you close the terminal, then you will also kill its child processes, and that means your application.

It is possible to prevent this behavior by issuing the "disown" command, that way you application is not considered a child of the terminal and you can close the latter without fear of also closing the former.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo 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