14

I don't know if the title is self explanatory, but I wanted to have multiple (two for now would be enough) terminals open without having to start the Desktop.

I want to have a PHP script running (full-time) and be able to still use my Raspi terminal as it is when I start my Raspi with Raspbian.

2
  • do you ssh or connect directly to your pi?
    – SteveIrwin
    Commented Apr 14, 2013 at 19:38
  • Hi what you may have wanted can be provided by dvtm. brain-dump.org/projects/dvtm
    – cgte
    Commented Mar 11, 2020 at 19:25

7 Answers 7

9

Just use Alt + F1-F12, so you can have 12 different console tabs without starting a GUI

3
  • this is actually the option I currently use :)
    – pasadinhas
    Commented Jul 24, 2014 at 14:51
  • 1
    This doesn't work on Raspbian, there's no login on any of the other ttys.
    – AndreKR
    Commented Jul 23, 2019 at 18:50
  • On the latest raspbian, the key sequence to toggle virtual consoles is ALT+SHIFT+F1 ..., ALT+SHIFT+F6. Special case: ALT+SHIFT+F7 toggles to the desktop. Commented Mar 9, 2022 at 14:11
10

If you're on the console (attached keyboard and screen) you should be able to use the Linux virtual console system to switch between multiple terminals using (ctrl-)alt-F1 through F12 and more with shift.

The number of terminals configured and the number of them having getty processes (that ask you for login and password) depends on configuration.

1
  • 3
    +1 because when directly connected to the machine, this is the "standard" way to get another login, and doesn't require installing screen/tmux..
    – Kiirani
    Commented Apr 24, 2013 at 1:45
9

Even better than screen is (in my opinion) tmux. You can install it via sudo apt-get install tmux. Also check out the manpage with man tmux.

You can start it by typing tmux on one of your consoles (see XTL's answer).

Here are the most important commands (C-b d means: press control and B at the same time, then press D):

  • C-b d detach session
  • tmux attach on the shell to re-attach a running session
  • C-b " split the current frame horizontally (new shell is started)
  • C-b % split the current frame vertically (new shell is started)
  • C-b arrow (up, down, left, right) navigate between windows in current frame
  • C-b c new frame (new shell is started)
  • C-b n next frame
  • C-b l last frame
  • C-b b send C-b to the running application
2
  • Strong advocate for tmux here, too. Status line configuration is much more simple and it handles redraws better.
    – coxley
    Commented Apr 15, 2013 at 22:33
  • 1
    Should be noted that tmux doesn't have the same behaviour as screen with regards to attaching the session to multiple VTs ("screen -x")
    – Kiirani
    Commented Apr 24, 2013 at 1:43
3

You can do this with screen also. With screen, you can even detach from your screen session, logout, login, then reattach to your screen session without losing anything. Programs will continue to run, and all output will continue to be shown on the terminals that you disconnected from.

A couple of links to screen tutorials:

http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/

http://magazine.redhat.com/2007/09/27/a-guide-to-gnu-screen/

A link to a thread with some useful .screenrc tips:

https://bbs.archlinux.org/viewtopic.php?id=55618

A Raspberry Pi specific tutorial:

http://raspi.tv/2012/using-screen-with-raspberry-pi-to-avoid-leaving-ssh-sessions-open

3
  1. If the php script you want to run doesn't interact with the user or needs input,

    you can use the & command which sends the script to the background

    Here is a example.

    pi@raspberrypi ~ $php code1 &
    

    This will send the script to the background where it will keep running.

  2. If you ssh into your terminal, then you can ssh in the same user twice and have two terminals.

  3. If you want to open multiple terminals from a ssh session,

    You should look at screen or even better install byobu which is a wrapper around screen.

    byobu is a wrapper that allows to easily open new screens with a simple function key instead of key combination from ctrl-a. It also shows a status line with all the open virtual terminals which can be named.

    Another nice feature is the fact that all your screen can stay up while your ssh connection is disconnected. You just connect again via ssh and call byobu and everything is like before.

Hope it helps.

0
3

For completeness, another option is to use byobu. It's a convenient layer on top of GNU screen. It provide nice defaults and it's in my sense easier to use. I personally use it on my Rapsberry Pi and it works just fine. To install it, just type:

$ sudo apt-get install byobu

Once installed, configure it via:

$ byobu-config

You can there choose to start it automatically when logging-in, and toggle status notification applets (uptime, load, date...)

enter image description here

As a side note, this kind of virtual console is also useful for sharing the same console input/output between different users on different machines (you can call it text mode screen sharing).

2
  • I tried byobou the other day and was not happy. The control via function keys was very flaky. Didn't work on OS X, also had problems when under Debian. I'll stick with tmux and its commands. The function keys also collide with mc (midnight commander).
    – Arne
    Commented Apr 22, 2013 at 21:58
  • As for the function key conflict with mc, you can change them on byobu (you can easily select between two different modes via byobu-config). Commented Jun 7, 2013 at 8:05
2

Since your original requirement was to launch a PHP script in the background, you can use the command nohup. Example:

$ nohup php myscript.php &

Once started, the command specified as a command-line argument to nohup is executed in the background, and its input/output are unlinked from the terminal who started it, to prevent the SIGHUP signal (hence the nohup name) to be sent to the background process when you quit the starting console (signal usually causing the program to quit). Output is redirected to a file (default nohup.out).

For more information: man nohup.

For a better and more complete answer, you may want to fully "daemonize" your program. You can probably find resources on the web which explain how to do it with PHP scripts.

1
  • Some shells (bash, zsh?) also have a command disown for preventing hanging up of selected background processes.
    – XTL
    Commented Apr 29, 2013 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.