View previous topic :: View next topic |
Author |
Message |
paradigm-X Apprentice
Joined: 19 Sep 2013 Posts: 168
|
Posted: Sat Feb 01, 2014 6:15 pm Post subject: Xterm & |
|
|
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 |
|
|
gotyaoi Tux's lil' helper
Joined: 01 Apr 2013 Posts: 137
|
Posted: Sun Feb 02, 2014 1:10 am Post subject: |
|
|
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 |
|
|
666threesixes666 Veteran
Joined: 31 May 2011 Posts: 1248 Location: 42.68n 85.41w
|
Posted: Sun Feb 02, 2014 1:20 am Post subject: |
|
|
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... |
|
Back to top |
|
|
Chiitoo Administrator
Joined: 28 Feb 2010 Posts: 2551 Location: Here and Away Again
|
Posted: Sun Feb 02, 2014 1:22 am Post subject: |
|
|
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. ^^ _________________ Kindest of regardses. |
|
Back to top |
|
|
paradigm-X Apprentice
Joined: 19 Sep 2013 Posts: 168
|
Posted: Sun Feb 02, 2014 9:00 pm Post subject: |
|
|
> "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 |
|
|
i92guboj Bodhisattva
Joined: 30 Nov 2004 Posts: 10315 Location: Córdoba (Spain)
|
Posted: Mon Feb 03, 2014 4:16 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
luismw Tux's lil' helper
Joined: 04 Jan 2010 Posts: 91
|
Posted: Tue Feb 04, 2014 9:43 am Post subject: |
|
|
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 |
|
|
|
|
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
|
|