ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.3 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://www.baeldung.com/linux/kill-detached-screen-session |
| Last Crawled | 2026-03-28 22:53:29 (9 days ago) |
| First Indexed | 2020-12-16 22:48:05 (5 years ago) |
| HTTP Status Code | 200 |
| Meta Title | How to Kill a Detached Screen Session | Baeldung on Linux |
| Meta Description | Learn how to kill a detached GNU screen session from the command line. |
| Meta Canonical | null |
| Boilerpipe Text | 1. Overview
When using
GNU
screen
, we can sometimes end up with detached sessions that need cleanup.
In this quick tutorial, we’ll walk through a few options for killing a detached
screen
session.
2. Listing Sessions
Before we start discussing how to end existing sessions, let’s first go through listing existing sessions. First, let’s set up a couple of sample screen sessions. In a bash shell, let’s type:
% screen -dmS my_session_1
% screen -dmS my_session_2
This will create two sessions named
my_session_1
and
my_session_2
. Notice we are not attached to either (thanks to the
-d
option). Now, let’s take a look at the sessions we created:
% screen -list
Our two sessions show up:
There are screens on:
84581.my_session_1 (Detached)
76340.my_session_2 (Detached)
Next, let’s talk about how to kill these sessions.
3. Attach and Kill a
screen
Session
One way we can kill aÂ
screen
session is to attach and then kill it. So, let’s attach to the first session we created above:
% screen -r my_session_1
Our command prompt is now inside our session. So we can just type:
%
exit
The session will end, and we should see:
[screen is terminating]
Now we only have one session left:
% screen -list
There is a screen on:
76340.my_session_2 (Detached)
If theÂ
screen
session had more than one window, we’d have to type
exit
 (or
CTRL+a k
) at every window before theÂ
screen
session would end
. An easier alternative is the
quit
command
:
CTRL+a \
(Note: you need to hold CTRL+a while hitting theÂ
\
key.) This prompts us with a confirmation:
Really quit and
kill
all your windows [y/n]
We choose to close all session windows to end theÂ
screen
session.
The above-attached scenario is straightforward because we created the
screen
session in the same window. Now,
if there’s another terminal or user attached to the session we want to kill, we need a different command to attach
. In our current terminal window, create a new session:
%
screen -S my_session_3
The
-S
will create the session and attach it to it. Now, let’s open a second terminal window and list ourÂ
screen
sessions:
% screen -list
There is a screen on:
19643.my_session_3 (Attached)
Notice this is now “Attached” because we are attached in our first terminal. In our second terminal, we’re going to force the session to detach from the first terminal window and attach to the second terminal. In the second terminal, type:
% screen -D -R my_session_3
Our second terminal is now in theÂ
screen
session. Our first terminal shows a warning and is back at the terminal:
[remote power detached]
Now we can useÂ
exit
as shown in the previous section.
4. Kill a
screen
Session Without Attaching
As an alternative to attaching to a session to end it, let’s look at a couple of ways to end aÂ
screen
session without attaching.
First, let’s create a couple of sessions to kill:
%
screen -dmS my_session_4
%
screen -dmS my_session_5
Our two sessions are now created:
% screen -list
There are screens on:
19665.my_session_4 (Detached)
19671.my_session_5 (Detached)
We can now
use the
screen
command argumentÂ
-X
to send a command to a running
screen
session
. TheÂ
-S
will allow us to specify the session that will receive the command. So, to send a
quit
command toÂ
my_session_4
, we would use:
%
screen -S my_session_4 -X quit
TheÂ
screen -list
shows our current sessions:
% screen -list
There is a screen on:
19671.my_session_5 (Detached)
Lastly, we can always
kill aÂ
screen
session via OS commands
. The numbers prepending the name are the PID of theÂ
screen
session. To kill our last session, we can use
kill
:
%
kill
19671
Checking ourÂ
screen
sessions now, we’ll see:
% screen -list
No Sockets found
in
/var/folders/wr/129xvd3dfecl/T/.screen.
5. Conclusion
In this article, we walked through various ways to kill a detachedÂ
screen
session. |
| Markdown | [](https://www.baeldung.com/linux/ "Baeldung")
- [](https://www.baeldung.com/linux/ "Baeldung")
- [Start Here](https://www.baeldung.com/linux/start-here)
- [Courses â–Ľâ–˛]()
- [Learn Java Collections Explore the Java Collections Framework and Algorithms](https://www.baeldung.com/courses/learn-java-collections-course)
- [Learn Spring From no experience to actually building stuff​](https://www.baeldung.com/courses/learn-spring-course)
- [Learn Maven Simplify your build with Apache Maven](https://www.baeldung.com/courses/learn-maven-course)
- [View All Courses](https://www.baeldung.com/members/all-courses)
- [Guides â–Ľâ–˛]()
- [Administration A collection of guides on Linux system administration](https://www.baeldung.com/linux/administration-series)
- [Scripting Basic and advanced scripting on Linux.](https://www.baeldung.com/linux/scripting-series)
- [Networking The building blocks for machine-to-machine communication](https://www.baeldung.com/linux/networking-series)
- [Files Deep dive into working with Files on Linux.](https://www.baeldung.com/linux/files-series)
- [Processes Learn about managing Linux processes and threads](https://www.baeldung.com/linux/processes-guide)
- [Pricing](https://www.baeldung.com/pricing)
- [About â–Ľâ–˛]()
- [Full Archive The high level overview of all the articles on the site.](https://www.baeldung.com/linux/full_archive)
- [About Baeldung About Baeldung.](https://www.baeldung.com/about)
# How to Kill a Detached Screen Session
Last updated: March 18, 2024

Written by: [Alex Tighe](https://www.baeldung.com/linux/author/alextighe "Posts by Alex Tighe")

Reviewed by: [Kevin Gilmore](https://www.baeldung.com/linux/editor/kevin-author "Reviewed by Kevin Gilmore")
- [Processes](https://www.baeldung.com/linux/category/processes)
- [kill](https://www.baeldung.com/linux/tag/kill)
## 1\. Overview
**When using [GNU *screen*](https://www.baeldung.com/linux/screen-command), we can sometimes end up with detached sessions that need cleanup.** In this quick tutorial, we’ll walk through a few options for killing a detached *screen* session.
## 2\. Listing Sessions
Before we start discussing how to end existing sessions, let’s first go through listing existing sessions. First, let’s set up a couple of sample screen sessions. In a bash shell, let’s type:
```
Copy
```
This will create two sessions named *my\_session\_1* and *my\_session\_2*. Notice we are not attached to either (thanks to the *\-d* option). Now, let’s take a look at the sessions we created:
```
% screen -listCopy
```
Our two sessions show up:
```
Copy
```
Next, let’s talk about how to kill these sessions.
## 3\. Attach and Kill a *screen* Session
One way we can kill a *screen* session is to attach and then kill it. So, let’s attach to the first session we created above:
```
% screen -r my_session_1Copy
```
Our command prompt is now inside our session. So we can just type:
```
% exitCopy
```
The session will end, and we should see:
```
[screen is terminating]Copy
```
Now we only have one session left:
```
Copy
```
**If the *screen* session had more than one window, we’d have to type *exit* (or *CTRL+a k*) at every window before the *screen* session would end**. An easier alternative is the [*quit* command](https://www.gnu.org/software/screen/manual/screen.html#Quit):
```
CTRL+a \Copy
```
(Note: you need to hold CTRL+a while hitting the *\\* key.) This prompts us with a confirmation:
```
Really quit and kill all your windows [y/n]Copy
```
We choose to close all session windows to end the *screen* session.
The above-attached scenario is straightforward because we created the *screen* session in the same window. Now, **if there’s another terminal or user attached to the session we want to kill, we need a different command to attach**. In our current terminal window, create a new session:
```
% screen -S my_session_3Copy
```
The *\-S* will create the session and attach it to it. Now, let’s open a second terminal window and list our *screen* sessions:
```
Copy
```
Notice this is now “Attached” because we are attached in our first terminal. In our second terminal, we’re going to force the session to detach from the first terminal window and attach to the second terminal. In the second terminal, type:
```
% screen -D -R my_session_3Copy
```
Our second terminal is now in the *screen* session. Our first terminal shows a warning and is back at the terminal:
```
[remote power detached]Copy
```
Now we can use *exit* as shown in the previous section.
## 4\. Kill a *screen* Session Without Attaching
As an alternative to attaching to a session to end it, let’s look at a couple of ways to end a *screen* session without attaching.
First, let’s create a couple of sessions to kill:
```
Copy
```
Our two sessions are now created:
```
Copy
```
We can now **use the *screen* command argument *\-X* to send a command to a running *screen* session**. The *\-S* will allow us to specify the session that will receive the command. So, to send a *quit* command to *my\_session\_4*, we would use:
```
% screen -S my_session_4 -X quitCopy
```
The *screen -list* shows our current sessions:
```
Copy
```
Lastly, we can always **kill a *screen* session via OS commands**. The numbers prepending the name are the PID of the *screen* session. To kill our last session, we can use [*kill*](https://www.man7.org/linux/man-pages/man1/kill.1.html):
```
% kill 19671Copy
```
Checking our *screen* sessions now, we’ll see:
```
Copy
```
## 5\. Conclusion
In this article, we walked through various ways to kill a detached *screen* session.

#### Categories
- [Scripting](https://www.baeldung.com/linux/category/scripting)
- [Installation](https://www.baeldung.com/linux/category/installation)
- [Search](https://www.baeldung.com/linux/category/search)
- [Web](https://www.baeldung.com/linux/category/web)
- [File Editing](https://www.baeldung.com/linux/category/files/editing)
- [File Searching](https://www.baeldung.com/linux/category/files/searching)
- [File Conversion](https://www.baeldung.com/linux/category/files/file-conversion)
- [Docker](https://www.baeldung.com/linux/category/docker)
#### Series
- [Linux Administration](https://www.baeldung.com/linux/administration-series)
- [Linux Scripting Series](https://www.baeldung.com/linux/linux-scripting-series)
- [Linux Files](https://www.baeldung.com/linux/files-series)
- [Linux Processes](https://www.baeldung.com/linux/processes-guide)
- [Linux Networking Tutorials](https://www.baeldung.com/linux/networking-series)
- [Linux Filesystem Guide](https://www.baeldung.com/linux/filesystem-guide)
- [Linux Security](https://www.baeldung.com/linux/security-series)
#### About
- [About Baeldung](https://www.baeldung.com/about)
- [Baeldung All Access](https://www.baeldung.com/courses)
- [The Full Archive](https://www.baeldung.com/linux/full_archive)
- [Editors](https://www.baeldung.com/editors)
- [Our Partners](https://www.baeldung.com/partners/)
- [Partner with Baeldung](https://www.baeldung.com/partners/work-with-us)
- [eBooks](https://www.baeldung.com/library/)
- [FAQ](https://www.baeldung.com/library/faq)
- [Baeldung Pro](https://www.baeldung.com/members/)
- [Terms of Service](https://www.baeldung.com/terms-of-service)
- [Privacy Policy](https://www.baeldung.com/privacy-policy)
- [Company Info](https://www.baeldung.com/baeldung-company-info)
- [Contact](https://www.baeldung.com/contact)
Privacy Manager


## Looks like your ad blocker is on.
Ă—
We rely on ads to keep creating quality content for you to enjoy for free.
Please support our site by disabling your ad blocker or, use **Baeldung Pro** for a clean, absolutely **no-ads** reading experience.
Disable
[Baeldung Pro](https://www.baeldung.com/members)
Continue without supporting us
#### Choose your Ad Blocker
- Adblock Plus
- Adblock
- Adguard
- Ad Remover
- Brave
- Ghostery
- uBlock Origin
- uBlock
- UltraBlock
- Other
1. In the extension bar, click the AdBlock Plus icon
2. Click the large blue toggle for this website
3. Click refresh
1. In the extension bar, click the AdBlock icon
2. Under "Pause on this site" click "Always"
1. In the extension bar, click on the Adguard icon
2. Click on the large green toggle for this website
1. In the extension bar, click on the Ad Remover icon
2. Click "Disable on This Website"
1. In the extension bar, click on the orange lion icon
2. Click the toggle on the top right, shifting from "Up" to "Down"
1. In the extension bar, click on the Ghostery icon
2. Click the "Anti-Tracking" shield so it says "Off"
3. Click the "Ad-Blocking" stop sign so it says "Off"
4. Refresh the page
1. In the extension bar, click on the uBlock Origin icon
2. Click on the big, blue power button
3. Refresh the page
1. In the extension bar, click on the uBlock icon
2. Click on the big, blue power button
3. Refresh the page
1. In the extension bar, click on the UltraBlock icon
2. Check the "Disable UltraBlock" checkbox
1. Please disable your Ad Blocker
Go Back |
| Readable Markdown | ## 1\. Overview
**When using [GNU *screen*](https://www.baeldung.com/linux/screen-command), we can sometimes end up with detached sessions that need cleanup.** In this quick tutorial, we’ll walk through a few options for killing a detached *screen* session.
## 2\. Listing Sessions
Before we start discussing how to end existing sessions, let’s first go through listing existing sessions. First, let’s set up a couple of sample screen sessions. In a bash shell, let’s type:
```
% screen -dmS my_session_1
% screen -dmS my_session_2
```
This will create two sessions named *my\_session\_1* and *my\_session\_2*. Notice we are not attached to either (thanks to the *\-d* option). Now, let’s take a look at the sessions we created:
```
% screen -list
```
Our two sessions show up:
```
There are screens on:
84581.my_session_1 (Detached)
76340.my_session_2 (Detached)
```
Next, let’s talk about how to kill these sessions.
## 3\. Attach and Kill a *screen* Session
One way we can kill a *screen* session is to attach and then kill it. So, let’s attach to the first session we created above:
```
% screen -r my_session_1
```
Our command prompt is now inside our session. So we can just type:
```
% exit
```
The session will end, and we should see:
```
[screen is terminating]
```
Now we only have one session left:
```
% screen -list
There is a screen on:
76340.my_session_2 (Detached)
```
**If the *screen* session had more than one window, we’d have to type *exit* (or *CTRL+a k*) at every window before the *screen* session would end**. An easier alternative is the [*quit* command](https://www.gnu.org/software/screen/manual/screen.html#Quit):
```
CTRL+a \
```
(Note: you need to hold CTRL+a while hitting the *\\* key.) This prompts us with a confirmation:
```
Really quit and kill all your windows [y/n]
```
We choose to close all session windows to end the *screen* session.
The above-attached scenario is straightforward because we created the *screen* session in the same window. Now, **if there’s another terminal or user attached to the session we want to kill, we need a different command to attach**. In our current terminal window, create a new session:
```
% screen -S my_session_3
```
The *\-S* will create the session and attach it to it. Now, let’s open a second terminal window and list our *screen* sessions:
```
% screen -list
There is a screen on:
19643.my_session_3 (Attached)
```
Notice this is now “Attached” because we are attached in our first terminal. In our second terminal, we’re going to force the session to detach from the first terminal window and attach to the second terminal. In the second terminal, type:
```
% screen -D -R my_session_3
```
Our second terminal is now in the *screen* session. Our first terminal shows a warning and is back at the terminal:
```
[remote power detached]
```
Now we can use *exit* as shown in the previous section.
## 4\. Kill a *screen* Session Without Attaching
As an alternative to attaching to a session to end it, let’s look at a couple of ways to end a *screen* session without attaching.
First, let’s create a couple of sessions to kill:
```
% screen -dmS my_session_4
% screen -dmS my_session_5
```
Our two sessions are now created:
```
% screen -list
There are screens on:
19665.my_session_4 (Detached)
19671.my_session_5 (Detached)
```
We can now **use the *screen* command argument *\-X* to send a command to a running *screen* session**. The *\-S* will allow us to specify the session that will receive the command. So, to send a *quit* command to *my\_session\_4*, we would use:
```
% screen -S my_session_4 -X quit
```
The *screen -list* shows our current sessions:
```
% screen -list
There is a screen on:
19671.my_session_5 (Detached)
```
Lastly, we can always **kill a *screen* session via OS commands**. The numbers prepending the name are the PID of the *screen* session. To kill our last session, we can use [*kill*](https://www.man7.org/linux/man-pages/man1/kill.1.html):
```
% kill 19671
```
Checking our *screen* sessions now, we’ll see:
```
% screen -list
No Sockets found in /var/folders/wr/129xvd3dfecl/T/.screen.
```
## 5\. Conclusion
In this article, we walked through various ways to kill a detached *screen* session. |
| Shard | 144 (laksa) |
| Root Hash | 17258965353624827544 |
| Unparsed URL | com,baeldung!www,/linux/kill-detached-screen-session s443 |