How to Kill a Detached screen Session in Linux
Last Updated :
22 Dec, 2022
The screen session is like virtual windows, And in Linux it works like a multiplexer terminal where we can create more than one window and work on that. we can create multiple windows inside one session. We called it virtual because the process will continue to run when their window will not be visible even if you have disconnected. Now, if we are working on more than one session in a virtual way then we also may need to kill them. So let's see how we can kill the screen sessions. While using the GNU screen or screen session, We can exit from the detached session that needs cleanup. In this article, we will talk about many options for killing a detached screen session.
Before going to discuss how to kill the existing session, let's go for listing the existing sessions.
Listing Sessions
First, let's create a couple of screen sessions by using the below command.
$ screen -dmS session_1
$ screen -dmS session_2
This will create two sessions named session_1 and session_2.
Notice that we have not attached this session because we have used -d. Now let's see the sessions that we have created.
For listing the created sessions, run the below command.
Command:
$ screen -list
Output:
Our two sessions show up:
Next, let's see how to kill these sessions.
There are two methods to kill the session:
- Method 1: Attach and kill the screen session.
- Method 2: Kill the screen session without attaching.
Let's discuss both methods
Method 1: Attach and kill the screen session.
First attach session_1 that we have created above, For that run the below command.
$ screen -r session_1
Now our command prompt is now inside our session. So we can just type:-
$ exit
The session will start terminating, and we can see [screen is terminating] in the output.
Now we have only one session left. That is session_2 because we have killed the session_1.
Output:
Note: If the screen session had more than one window, we have to type exit at every window before the screen session would end.
Method 2: Kill the screen session without attaching.
In this method, we will not attach the session. Let's look up the way to kill the screen session without attaching them.
First, create a couple of screen sessions to kill.
$ screen -dmS session_3
$ screen -dmS session_4
Now, our two screen sessions have been created. Let's list the session by using the below command.
$ screen -list
Output:
Now, we will use the screen command argument -X to send the command in a running screen version. The -S will allow us to specify the session that we want to kill. And for killing that particular session, we will add the quit command.
$ screen -S session_3 -X quit
Now, the screen session_3 has been killed. Let's list our current sessions by using the below command.
$ screen -list
Output:
We can see that we have only session_4 because we have killed the session_3.
Conclusion:
In this article, we have discussed multiple methods to kill a Detached screen Session in Linux. In the first method, first, we have to attach the screen session, and then we can kill that. In the second, method we have seen that we can kill the screen session without attaching that.
Similar Reads
How to Kill a Process in Linux | Kill Command
kill command in Linux (located in /bin/kill), is a built-in command which is used to terminate processes manually. kill command sends a signal to a process that terminates the process. If the user doesn't specify any signal that is to be sent along with the kill command, then a default TERM signal i
6 min read
How to Kill Processes by Given Partial Names in Linux
On a Unix system creates a separate environment for a program when it is executed. Everything the system needs to run the program as if there were no other programs in this environment. In Unix, each command you issue initiates or starts a new process. You initiated a process using the ls command to
4 min read
How to Kill a Process Running on Particular Port in Linux?
Have you ever tried to launch a web server, database, or application in Linux, only to be stopped by the frustrating âAddress already in useâ error? This happens when another process is already occupying the required port, preventing your application from running. Freeing up the port is crucial to e
6 min read
How to kill all processes in NodeJS?
To kill all Node.js processes In Node.js you can use process.kill method, you can list all running processes, filter out the Node.js processes, and then use process.kill to terminate each identified process. process.killThe process.kill( pid[,signal] ) is an inbuilt technique in node.js that conveys
3 min read
How to List Running Processes in Linux | ps Command
As we all know Linux is a multitasking and multi-user system. So, it allows multiple processes to operate simultaneously without interfering with each other. Process is one of the important fundamental concepts of the Linux OS. A process is an executing instance of a program that carries out differe
10 min read
How to Start and Quit a Scala REPL Session?
Scala REPL (Read-Eval-Print Loop) is an interactive shell where you can directly execute Scala code snippets and see the results immediately. It's a tool that allows you to experiment with Scala code, test small code snippets, and explore the behavior of Scala constructs without having to compile an
2 min read
screen command in Linux with Examples
The screen command is an advanced terminal multiplexer that allows you to have multiple sessions within one terminal window. It's like having "tabs" in your Linux terminal â you can open, detach, switch, or resume sessions at any time without losing what you're working on. It's particularly convenie
7 min read
Easy way to kill process using Fkill in Linux
fkill-cli is a command-line-based tool to kill processes interactively. Fkill is developed using Nodejs. It can run on different operating systems like macOS, Linux, and Windows. To kill the process using fkill we just have to mention the process name or the process PID. Fkill can also be used to ki
3 min read
How do I keep a session alive for long Selenium scripts in automation?
In Selenium automation, maintaining a session for extended periods can be challenging, especially when running long-running scripts or data scraping tasks. A common issue is that sessions can expire or time out, disrupting automated workflows. To ensure your tests or automation scripts continue runn
4 min read
How to Clear The Screen on Putty
PuTTY is a free and open-source terminal emulator. It is used to connect to remote hosts and devices using various network protocols (SSH and Telnet are the most common ones). PuTTY is mainly used by system administrators and IT professionals for quick remote access to servers. Its lightweight desig
3 min read