Today's Deals (in Amazon.com)

 Question:

raspbian - Open multiple "Terminals" without GUI (startx)
  • Miguel

    I dont 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.

  •  Answers:

  • Clare Macrae
    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.

  • Arne

    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
  • Eric

    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

  • XTL

    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.

  • lOranger

    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).

  • lOranger

    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.