Search code examples
linuxbashtimeserver

How to find out how long a screen command has been running on Linux?


I'm running a long script on a Linux server. To avoid getting kicked due to inactivity, I used screen to make sure the script runs to termination. It's been a few hours now and I'd like to know how long exactly the screen has been active for. The command I launched the screen with is screen -S fragmentation ./fragment-all.sh. I do not have root privilege.

yangsong@lanikai ~ $ screen -ls
There is a screen on:
        852342.fragmentation    (Detached)
1 Socket in /tmp/screen/S-yangsong.

Solution

    1. Hi cannot comment (yet) so ill try to answer here.
    2. You can find the process id of the screen command that running by using pgrep screen. (process grep screen).
      • if you can't find the screen process by this command, then you can use top command to see all the process that running and look for screen process with his own PID (process id).
    3. The output should be a number within few digits.
    4. Then you can run the command ps -o etime= -p "PID" to see how much time the process is running.
      • change PID with the process id you have got from pgrep screen command.
      • The output should be the elapsed time in the format [[dd-]hh:]mm:ss.
    5. If you want to terminate the process you can execute the command kill PID.
      • change the PID with the process id that you want to terminate.
    6. Another method that i prefer, because she is more readable is:
      • ps -o stime,time PID
      • the output should be something like that:
      • STIME TIME
      • 15:52 00:21:45