Home > Online Help > Unix > Unix Command: Screen

Unix Command: Screen


  • Introduction
  • How to Use Screen to Run Jobs Remotely

  • Introduction

    The Unix screen utility is a full-screen window manager that allows you to run several virtual terminals within Unix.

    It allows users to re-attach sessions in case a connection is lost. It also allows users to detach sessions when logging off, and re-attach sessions to resume where they originally left off.

    For the purpose of running jobs remotely, we are going to focus on screen's functions of detaching and attaching sessions.

    How to Use Screen to Run Jobs Remotely

    To start the screen utility, simply issue the following command:
    We are going to focus on the following screen commands:

    *Note that Ctrl-a c means while holding "Ctrl", hit "a", then hit "c"

    Ctrl-a c Create a new screen
    Ctrl-a k Terminate the current screen
    Ctrl-a w List all screens
    Ctrl-a d Detach current screen

    Here's an exmaple:

    Let's say a user, Oski, wants to run Matlab in the background on the machine makalu. Oski will first ssh to makalu, then start screen. Next, he will simply issue the Matlab command with no GUI (i.e. /usr/bin/nohup matlab-nogui < inputfile > outputfile). Oski's Matlab job should start to run and he should see some output being displayed on screen.

    Now, Oski needs to go to class and cannot leave his computer connected. He can detach the screen and log out while the job continues to run. To do that, Oski will issue the detach current screen command:

    Ctrl-a d
    Now, Oski has detached the screen session he was using. The Matlab job is still running on the server. But now, Oski can disconnect his computer from the server, and head to class.

    Now, Oski has a chance to go back to his Matlab job, he simply ssh back to makalu, and issues the following command to see all the screens that are running:

    screen -list
    Oski should see:
    There is a screen on:
    	19494.pts-5.makalu      (Detached)
    1 Socket in /tmp/uscreens/S-oski.
    It is showing that Oski is having 1 detached screen (with PID 19494) running on makalu.

    Now, Oski wants to re-attach the detached screen to track his Matlab job, he simply issues:

    screen -r 19494
    Oski will then resume his Matlab job screen and with the output being display on screen.

    To see more commands available within the screen manager, issue:

    man screen


    Comments to consult@newton.berkeley.edu
    © 1998-2019 UC Regents