- How to close the Terminal?
- 3 Answers 3
- How to close terminal with my program?
- 1 Answer 1
- close the terminal without terminating the process
- 1 Answer 1
- How can I run a command which will survive terminal close?
- 11 Answers 11
- Arch Linux
- #1 2011-12-19 08:43:02
- (SOLVED) Closing a terminal window
- #2 2011-12-19 08:44:47
- Re: (SOLVED) Closing a terminal window
- #3 2011-12-19 09:29:14
- Re: (SOLVED) Closing a terminal window
- #4 2011-12-19 09:32:13
- Re: (SOLVED) Closing a terminal window
- #5 2011-12-19 13:01:34
- Re: (SOLVED) Closing a terminal window
- #6 2011-12-19 19:03:28
- Re: (SOLVED) Closing a terminal window
- #7 2011-12-19 20:01:27
- Re: (SOLVED) Closing a terminal window
- #8 2011-12-19 22:24:46
- Re: (SOLVED) Closing a terminal window
How to close the Terminal?
I found many questions about how to open the terminal but cant find a question with an answer on how to close the terminal and return back to the desktop of Ubuntu (note: I am on virtual machine)
3 Answers 3
You can type exit . You can type ctrl — d . Or (if you’re on a virtual terminal), you use ctrl — alt — F8 .
ctrl + shift + w closes the current tab and ctrl + shift + q closes the entire window.
This is similar to other commands that also are normally ctrl + whatever such as, ctrl + c and ctrl + v for copy and paste which, in gnome-terminal are, ctrl + shift + c and ctrl + shift + v respectively.
I’m not sure if the following works in a virtual machine, however, it is important to also note that when you switch to a tty text session such as tty1 — tty6 using ctrl + alt + f1 up to ctrl + alt + f6 , you can return to the regular desktop xsession by pressing ctrl + alt + f7 typically or sometimes ctrl + alt + f8 .
TL;DR: Press Alt + F7 .
You are apparently asking how to close a virtual console, also known as a virtual terminal—a full-screen text terminal you got to by pressing a key combination like Ctrl + Alt + F1 , Ctrl + Alt + F2 , and so forth.
In infer this since you say you wish to «return back to the desktop of Ubuntu» (indicating you are not on your desktop now) and, in a comment, wrote:
my terminal in virtual machine is at a black background and when i type exit it refreshes its not a program .
Rather than actually closing your text-based virtual console, you probably just want to get back to the virtual console on which the graphical user interface is running. This is usually the seventh virtual console, so press Alt + F7 . ( Ctrl is optional when switching from a virtual console that does not have the GUI running on it; however, you must use it when switching from a virtual console that does have the GUI running on it.)
If those key combinations do not work—or change the virtual console of the host rather than the guest—and your Ubuntu system is a VirtualBox guest system, see How do I switch between virtual terminals in a guest system? as suggested by LiveWireBT.
Another way, which is much less often used, is to run the command chvt 7 .
Источник
How to close terminal with my program?
The problem is that my program do the scan, but the terminal remains open, i compile and run my program with termianl using: gcc auto.cpp -o auto.exe to compile, and ./auto.exe to run. I try to use system(«exit») but it doesn’t work. P.S. sorry for my bad english.
1 Answer 1
Although you can not make your compiled application close the terminal window in which it is running, it is easy to make this happen by changing the way how you execute your program.
For example, if your executable application can be started using ./myprogramm , you could just type the command below in your terminal to first run myprogramm and as soon as it finishes, run the exit command to close the shell and with it the whole terminal window:
Or maybe it would be even better to only close the terminal window if your application exited successfully, without any error (indicated by an exit status code other than 0). You can use && instead of ; to run the second command only if the first command was successful:
A third alternative would be to replace the shell running in your terminal window with your application, instead of running your application inside the shell. That way, the terminal window will close as soon as your application exits and you don’t have to exit the shell at that point any more:
One big difference between the first two approaches ( ; exit and && exit ) and the last one using exec is, that in the first case, you can kill the command you ran by hitting Ctrl + C and you will be back in the shell, the window will stay open. If you used exec , this will also kill your application, but as there is no more shell inside which it is running, the terminal window will close immediately as well.
Источник
close the terminal without terminating the process
I started an installation process from a terminal and have two questions about this:
- How can I close the terminal without terminating the installation process? and how can I restore it again?
- How can I figure that this terminal has finished processing from another terminal so that I can do other processes based on the result of the first terminal?
1 Answer 1
For 1. you need to send your running process to the background and remove the associated job from current shell.
- Press Ctrl + Z and type bg to send the installation process to the backgroud
- then type disown .
You can now close the terminal, the process will still be alive. You can open another terminal and check its process id with ps -aef
In my case the process id is 14426 . Unfortunately there’s no easy way to reattach it to another terminal (See How to attach terminal to detached process?) unless you used something based on screen .
For 2. You can use the following command:
It will print ok when the process is over from an other terminal. You can of course change this echo command with something more complex.
Источник
How can I run a command which will survive terminal close?
Sometimes I want to start a process and forget about it. If I start it from the command line, like this:
I can’t close the terminal, or it will kill the process. Can I run a command in such a way that I can close the terminal without killing the process?
11 Answers 11
One of the following 2 should work:
See the following for a bit more information on how this works:
If your program is already running you can pause it with Ctrl-Z , pull it into the background with bg and then disown it, like this:
Good answer is already posted by @StevenD, yet I think this might clarify it a bit more.
The reason that the process is killed on termination of the terminal is that the process you start is a child process of the terminal. Once you close the terminal, this will kill these child processes as well. You can see the process tree with pstree , for example when running kate & in Konsole:
To make the kate process detached from konsole when you terminate konsole , use nohup with the command, like this:
After closing konsole , pstree will look like this:
and kate will survive. 🙂
An alternative is using screen / tmux / byobu , which will keep the shell running, independent of the terminal.
You can run the process like this in the terminal
Though all of the suggestions work well, I’ve found my alternative is to use screen , a program that sets up a virtual terminal on your screen.
You might consider starting it with screen -S session_name . Screen can be installed on virtually all Linux and Unix derivatives. Hitting Ctrl + A and (lower case) C will start a second session. This would allow you to toggle back and forth between the initial session by hitting Ctrl + A and 0 or the newer session by hitting Ctrl + A and 1 . You can have up to ten sessions in one terminal. I used to start a session at work, go home, ssh into my work machine, and then invoke screen -d -R session_name . This will reconnect you to that remote session.
# screen -ls There is a screen on: 10803..Server-station (Detached) 1 Socket in /root/.screen.
Источник
Arch Linux
You are not logged in.
#1 2011-12-19 08:43:02
(SOLVED) Closing a terminal window
When I am through using the terminal window, I hit the X at the top right corner but get this message: There is still a process running in this terminal. Closing the terminal will kill it.
Why do I get this? I think I have nothing running. is there a bug?
Last edited by mcduling (2011-12-19 22:23:54)
#2 2011-12-19 08:44:47
Re: (SOLVED) Closing a terminal window
Sometimes, the warning is useful.
But maybe in your case, it’s a genuine bug — well how should anyone know if you don’t give the steps to reproduce it?
#3 2011-12-19 09:29:14
Re: (SOLVED) Closing a terminal window
I open the terminal. Type su to change to root. Enter password, Then close the terminal by hitting the X and get the message.
#4 2011-12-19 09:32:13
Re: (SOLVED) Closing a terminal window
It is complaining because you are still running su. That’s a fair warning, not a bug.
If you don’t like it, use sudo instead. It’s safer anyway than leaving a terminal sitting around in su-mode for arbitrary lengths of time.
Edit: btw, if you have run su to gain root access, and you want to close the terminal, you can get out of su by typing «exit». Then you should be able to close the terminal.
But really, don’t use su. That’s just asking for trouble. Sudo is your friend.
Last edited by /dev/zero (2011-12-19 09:59:43)
#5 2011-12-19 13:01:34
Re: (SOLVED) Closing a terminal window
Of course the best way is to just press CTRL-d, that exit the shell (first the root login from su, then upon pressing ctrl-d again it closes the terminal), it’s even faster than clicking any window decoration «X»
(my-dotfiles)
«People willing to trade their freedom for temporary security deserve neither and will lose both.» — Benjamin Franklin
«Enlightenment is man’s leaving his self-caused immaturity.» — Immanuel Kant
#6 2011-12-19 19:03:28
Re: (SOLVED) Closing a terminal window
Of course the best way is to just press CTRL-d, that exit the shell (first the root login from su, then upon pressing ctrl-d again it closes the terminal), it’s even faster than clicking any window decoration «X»
Oh, ctl-d works to close the terminal? I’ve been typing exit all this time o_O
Learn something new every day 🙂
#7 2011-12-19 20:01:27
Re: (SOLVED) Closing a terminal window
I often get this in gnome-terminal and xfce terminal for some reason. I’ve switched to lxterminal which always just closes when I click the button. (And I use sudo not su)
Last edited by bwat47 (2011-12-19 20:02:06)
#8 2011-12-19 22:24:46
Re: (SOLVED) Closing a terminal window
Thanks everyone. Great advise and good to learn. Arch is becoming addictive here.
Источник