kill a screen session

602,352

Solution 1

first you need to re attach to the screen session
screen -r 23520 as you have done. Then press ctrl + a and then a k and press y when it asks if you really want to kill the session

Source

Solution 2

  1. Identify the name of the session:
 $ screen -ls
  1. Close a session:
$ screen -XS <session-id> quit
  • Rationale: -X = Execute command, -S session PID to execute on
  • Example: screen -XS 20411 quit
  • Source: innaM's Answer

Solution 3

This command will kill all screen sessions, if that is desired:

So with all those official suggestions, I have one here that i feel is easier, and just as effective, and kind of more straight forward:

pkill screen

Who wants to go into an unknown and un-needed screen just to press in a couple commands that most might barely remember? This avoids going into it at all, and kills it straight off.

Plus, if you have more than one, this will take them all in one fell swoop.

Solution 4

This will kill all the detached screens:

screen -ls | grep detached | cut -d. -f1 | awk '{print $1}' | xargs kill

This will kill all screens, attached or detached

screen -ls | grep pts | cut -d. -f1 | awk '{print $1}' | xargs kill

Solution 5

Like you, I wanted to kill my screen session and found the documentation unhelpful. Convinced that there must be a keyboard shortcut, I found that
ctrl + a then \
works

I then get the prompt: "Really quit and kill all your windows [y\n]"

I am not sure why the documentation says ctrl + a then ctrl + \. That doesn't do anything for me.

Share:
602,352

Related videos on Youtube

JohnMerlino
Author by

JohnMerlino

Looking to master Trigonometry and Calculus and an interest in Ruby and JavaScript programming languages. I only use Linux (in particular Ubuntu Desktop) and Android. I like to write as well.

Updated on September 18, 2022

Comments

  • JohnMerlino
    JohnMerlino over 1 year

    I'm trying to kill a screen session. I noticed a lot of other related questions, but none of those answers are working for me. I am trying to kill the following session:

    screen -ls
    There is a screen on:
        23520.pts-6.porkypig    (09/30/2013 02:49:47 PM)    (Detached)
    1 Socket in /var/run/screen/S-root.
    
    screen -r 23520.pts-6.porkypig
    

    Now I am in the session. According to the documentation:

    http://www.gnu.org/software/screen/manual/screen.html#Quit

    I am supposed to press "control a" and then "control \". I do that and nothing happens.

    Another solution said to press Ctrl+a and type :quit. However, again it doesn't do anything. In fact, pressing control+a, absolutely nothing happens afterwards except a message "No Other Window"

    • Admin
      Admin over 9 years
      in screen v4.x, to kill all sessions, ps aux | grep "SCREEN" | awk '{print $2}' | xargs kill
    • Admin
      Admin over 7 years
      For the record, you can just do screen -r porkypig or screen -r 23520, rather than having to include the full string. Screen names are supposed to make things easier, not more complicated.
    • Admin
      Admin about 3 years
      we can also use the exit command to terminating screen
  • Mikkel
    Mikkel over 7 years
    This works if there is a problem with a process running inside the screen, but not if there is a problem with screen itself. That is the case 99% of the time, and has the added benefit of only affecting a single window within the screen rather than terminating all windows.
  • Mikkel
    Mikkel over 7 years
    Note that this will kill all running screens, which may or may not be what you want.
  • AJ.
    AJ. over 7 years
    This was pretty simple. You can simplify it even more by combining the -X -S with -XS
  • Martin Thoma
    Martin Thoma almost 7 years
    You should give credit to innaM answer if you copy it
  • kRazzy R
    kRazzy R over 6 years
    After 6 hours breaking my head all over internet... yours was the only answer that worked. Thanks mate!
  • MAChitgarha
    MAChitgarha over 5 years
    Not a good choice. I've been doing it for some time. Sometimes it causes bad behaviors (e.g. logging out from your user account immediately). Also, as @Mikkel mentioned, it could cause to close all your screens, which would not be what you want. Sometimes you need to keep running some (e.g. some are running by system) and stop some other screens.
  • Eric Wang
    Eric Wang over 4 years
    It is to kill a window, not a session
  • birgersp
    birgersp about 3 years
    Is there a way to kill the session without having to answer the prompt? I'd rather skip the y part.
  • avia
    avia almost 3 years
    This answer is most probably the most straightforward, quick yet efficient one.
  • gillesC
    gillesC almost 3 years
    Easiest and most straightforward approach! You will, of course, first need to reattach to the screen session.
  • Coljac
    Coljac about 2 years
    This doesn't answer the question (how to kill a screen session, as opposed how to exit normally) and it doesn't expand on the other answers. A good answer might cover the normal exiting procedure and then document a few ways you can kill screen if that doesn't work.
  • user2965003
    user2965003 about 2 years
    Ctrl + a then UPPERCASE K, then y