Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

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.

share|improve this question
    
do you ssh or connect directly to your pi? –  SteveIrwin Apr 14 '13 at 19:38

7 Answers 7

up vote 1 down vote accepted

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

share|improve this answer
    
this is actually the option I currently use :) –  pasadinhas Jul 24 at 14:51

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.

share|improve this answer
1  
+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 1:45

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
share|improve this answer
    
Strong advocate for tmux here, too. Status line configuration is much more simple and it handles redraws better. –  codey Apr 15 '13 at 22:33
    
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 1:43

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

share|improve this answer
  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.

share|improve this answer
    
Thanks, the solution I was looking for is the 1st one! –  pasadinhas Apr 14 '13 at 20:38

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

share|improve this answer
    
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). –  lOranger Jun 7 '13 at 8:05

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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