I have both a ruby script and a qt executable. Both of them pretty much accomplish same task but listen on different ports. Basically, they are UDP socket servers listening for incoming connections on a specified port on my remote ubuntu server. They listen for UDP packets coming in from GSM modems of GPS devices. Now right now I can ssh into my remote server and run the ruby script to begin listening for connections to said port: "ruby server.rb". But as soon as I log out and close the ssh connection, the script presumably stops listening. I want this script to continue listening for incoming connections on that port forever, even after I log out of server.

For example:

sudo netstat -tulpn 
tcp        0      0  *               LISTEN      25391/mysqld    

That mysqld server listens constantly for incoming connections to port 3306. I want my script to do the same thing. I want to be able to run netstat and always see my program running and listening on a specified port.

What is the best approach to take in this situation? Create a daemon? Or use nohup?

1 Answer 1


Use a program called screen.

Install it on the server and run screen and any program that runs will remain active on the server.

To install it run

sudo apt-get install screen

More details about other commands here http://www.kuro5hin.org/story/2004/3/9/16838/14935

  • hi this is interesting answer, is screen the same thing as byobu? Because someone else wrote an application that does something similar on my server but they did it in byobu. But I think screen is same thing? I didn't realize that's what it's for. May 31, 2013 at 14:19
  • @JohnMerlino ITs not a Terminal screen multiplexor. Its a program that makes things stay in memory its like issuing the nohup command except that when you exit the ssh session and return you will actually see the output of the command in a nicer way. It's like putting your terminal session in the background. I use it to maintain servers as you can even cut and paste text using just cursor keys. Very good program to learn. Available on every distro I know
    – Meer Borg
    May 31, 2013 at 15:43
  • In the link you sent me, the very first line says "Screen is best described as a terminal multiplexer. " Jun 1, 2013 at 0:53
  • Later on in that article it says " With a bit of extra work, you can even have a number of terminals all attached to the same session--great for collaborative efforts and meetings. " Isn't that by definition a terminal screen multiplexor? Jun 1, 2013 at 1:17
  • @JohnMerlino What I was trying to say was that its not a terminal with lots of windows. Probably should have stated that more clearly, you are right!
    – Meer Borg
    Jun 1, 2013 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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