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.

Glorfindel
  • 620
  • 1
  • 8
  • 15
pasadinhas
  • 153
  • 1
  • 2
  • 7

7 Answers7

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.

XTL
  • 1,389
  • 9
  • 22
  • 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 Apr 24 '13 at 01:45
9

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

nnm
  • 106
  • 1
  • 1
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
Arne
  • 2,226
  • 2
  • 18
  • 35
  • Strong advocate for tmux here, too. Status line configuration is much more simple and it handles redraws better. – coxley Apr 15 '13 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 Apr 24 '13 at 01:43
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.

Clare Macrae
  • 275
  • 2
  • 11
SteveIrwin
  • 1,718
  • 2
  • 18
  • 31
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

Eric
  • 81
  • 5
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).

  • 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 Apr 22 '13 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). – Laurent Grégoire Jun 07 '13 at 08: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.

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