Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have multiple screens running on an Ubuntu server that are initiated as:

screen -dmS screen1 cmd
screen -dmS screen2 cmd
etc...

And I need to kill one screen, but not all of them. What is the correct command to kill a single particular screen with its name? I've read through the man pages but I can't seem to find the command I am looking for.

Also I want to write this command into a bash script so I can't simply screen -r screen1 then press Ctrl+X as I normally would.

share|improve this question
    
Sorry, thought this was about Donkey Kong for a second –  Chopper3 Dec 21 '09 at 18:46
    
I love this t-shirt ohgizmo.com/wp-content/uploads/2008/11/… –  Chopper3 Dec 21 '09 at 18:57
    
That is a nice tee, most people won't get it thou, unless they've seen "The King of Kong": imdb.com/title/tt0923752 –  BassKozz Dec 21 '09 at 19:07
    
The correct word for an object of a phrase is "thee". –  Dennis Williamson Dec 21 '09 at 19:12
2  
You said "get it thou" here and "Thanks thou" below. It should be "get it [for] thee" and "Thanks [be to] thee". –  Dennis Williamson Dec 21 '09 at 23:08
show 1 more comment

3 Answers

up vote 6 down vote accepted

From the man page :

   -X   Send the specified command to a running screen  session.  You  can
        use  the  -d or -r option to tell screen to look only for attached
        or detached screen sessions. Note that this command  doesn't  work
        if the session is password protected.

You can do :

        screen -X -S <sessionid> kill
share|improve this answer
    
PERFECT!!! Thanks defraagh, musta missed that in the man. –  BassKozz Dec 21 '09 at 19:05
    
Good to know :-) –  ℝaphink Dec 21 '09 at 20:05
add comment

If you do a screen -list, you'll notice that each screen name begins with a number, which is the PID of the screen:

 $ screen -list
There are screens on:
        12281.pts-1.jonah       (12/21/2009 07:53:19 PM)        (Attached)
        10455.pts-1.jonah       (12/19/2009 10:55:25 AM)        (Detached)
2 Sockets in /var/run/screen/S-raphink.

From there, just send a KILL signal to this specific PID:

$ kill 12281

and it will kill the specific screen.

share|improve this answer
    
this won't work because I am running it from a bash script, and I rather not have to pull the PID from screen -list that matches the correct screen... defraagh's answer above worked like a charm. Thanks thou. –  BassKozz Dec 21 '09 at 19:03
    
Ok, good that defraagh had a perfect solution for it. –  ℝaphink Dec 21 '09 at 20:05
add comment

defraagh's solution doesn't work for me, however I can kill the screen session using Raphink's idea:

screen -list get the process ID

kill -9 PROCESSID

screen -wipe SESSIONID

share|improve this answer
add comment

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.