{"id":23182,"date":"2023-11-20T07:40:19","date_gmt":"2023-11-20T07:40:19","guid":{"rendered":"https:\/\/linuxways.net\/?p=23182"},"modified":"2023-12-14T05:51:47","modified_gmt":"2023-12-14T05:51:47","slug":"kill-screen-session","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/debian\/kill-screen-session\/","title":{"rendered":"How to Kill a Screen Session in Linux?"},"content":{"rendered":"<p>Sessions on Linux are the shells that allow to interact the user with the system, thus acting as a bridge between the user and the kernel of the system. In the shell, there are multiple processes that are running and are referred to as a process group. In Linux screen sessions are a sort of multiplexer terminals as users can open up multiple terminal sessions which aids in multitasking. Moreover, these terminals can be opened in a single terminal window and can be detached depending on the utility.<\/p>\n<p>The processes in the screen window will continue to run in the background even if the window is closed, which can consume a lot of system resources, thus leading to system instability. Therefore, it is necessary to kill the screen session once you have closed it.<\/p>\n<h2><strong>How to Kill a Screen Session<\/strong><\/h2>\n<p>Every process on Linux has its process ID through which it can be identified and can be used to terminate the respective process. Moreover, like the process ID, there is a session ID for each session running on Linux and there are numerous ways to kill the screen session:<\/p>\n<ul>\n<li><a href=\"#post-23182-2rm1cpwx32ut\"><strong>Through kill command<\/strong><\/a><\/li>\n<li><a href=\"#post-23182-89vewv7eglfg\"><strong>Through screen command<\/strong><\/a><\/li>\n<li><a href=\"#post-23182-v9tcafvv3nw\"><strong>Through pkill command<\/strong><\/a><\/li>\n<li><a href=\"#post-23182-uiwfm4cjsspg\"><strong>Attach and exit the session<\/strong><\/a><\/li>\n<\/ul>\n<h2><a id=\"post-23182-2rm1cpwx32ut\"><\/a><strong>Method 1: Through Kill Command<\/strong><\/h2>\n<p>The kill command is the built-in shell in Linux which is used to terminate the processes and sessions using their respective IDs. This command just sends the signal to process based on the options used with this command. By default, this command takes the -15 option if not specified, that is the signal of termination of the process. To kill the screen session on Linux using this kill command, here are some steps that should be followed:<\/p>\n<h3><strong>Step 1: Get the session ID <\/strong><\/h3>\n<p>To terminate or end any screen session on Linux, it is necessary to get the session ID for the respective session and for that, the following command is used:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">ps<\/span> <span class=\"re5\">-ef<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">grep<\/span> <span class=\"sy0\">&lt;<\/span>screen-session-name<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>Here,<\/p>\n<ul>\n<li>The ps is for displaying the information of running screen sessions.<\/li>\n<li>The flag e is for listing all the screen sessions either currently running or running in the background.<\/li>\n<li>The flag f is used to display the full information for all the processes running.<\/li>\n<li>The grep is used for searching the sessions with the given name.<\/li>\n<\/ul>\n<p>Now for demonstration, I have listed the screen session using the above given command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">ps<\/span> <span class=\"re5\">-ef<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">grep<\/span> <span class=\"kw2\">screen<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"848\" height=\"291\" class=\"wp-image-23184\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-1.png 848w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-1-300x103.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-1-768x264.png 768w\" sizes=\"auto, (max-width: 848px) 100vw, 848px\" \/><\/p>\n<h3><strong>Step 2: Kill the session using session ID<\/strong><\/h3>\n<p>Once you have got the session ID execute the kill command to end the session process and here is the syntax for it:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">Kill <span class=\"br0\">&#91;<\/span>option<span class=\"br0\">&#93;<\/span> <span class=\"sy0\">&lt;<\/span>session-id<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>Here the option defines the type of signal to be sent to the session and there are three options that can be used with the kill command and those are:<\/p>\n<table width=\"624\">\n<tbody>\n<tr>\n<td width=\"161\"><strong>Name of Signal <\/strong><\/td>\n<td width=\"161\"><strong>Number of Signal <\/strong><\/td>\n<td width=\"302\"><strong>Description <\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"161\">SIGTERM<\/td>\n<td width=\"161\">15<\/td>\n<td width=\"302\">Terminates the session or process, leaving the child processes.<\/td>\n<\/tr>\n<tr>\n<td width=\"161\">SIGKILL<\/td>\n<td width=\"161\">9<\/td>\n<td width=\"302\">It kills the session or process immediately, along with the child process.<\/td>\n<\/tr>\n<tr>\n<td width=\"161\">SIGHUP<\/td>\n<td width=\"161\">1<\/td>\n<td width=\"302\">Notifies the serial line drop process.<\/td>\n<\/tr>\n<tr>\n<td width=\"161\">SIGINT<\/td>\n<td width=\"161\">2<\/td>\n<td width=\"302\">Interprets the process<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>By default, as mentioned above the option is set to 15 which means the termination of the screen session or process. Now use the above syntax to kill the screen session:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">Kill <span class=\"re5\">-15<\/span> <span class=\"nu0\">2884<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"288\" class=\"wp-image-23185\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-2.png 859w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-2-300x101.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-2-768x257.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/p>\n<h3><strong>Kill all the Screen Sessions<\/strong><\/h3>\n<p>This method is viable if you want to kill all the screens simultaneously, so just execute the killall command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">killall<\/span> <span class=\"re5\">-15<\/span> <span class=\"kw2\">screen<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"846\" height=\"304\" class=\"wp-image-23186\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-3.png 846w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-3-300x108.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-3-768x276.png 768w\" sizes=\"auto, (max-width: 846px) 100vw, 846px\" \/><\/p>\n<h2><a id=\"post-23182-89vewv7eglfg\"><\/a><strong>Method 2: Through screen Command <\/strong><\/h2>\n<p>The primary function of the screen command is to display multiple screens on Linux and can also be used to kill the screen session on Linux. On Linux to kill a screen session there are some steps to be followed to use the screen command for terminating the screen session:<\/p>\n<h3><strong>Step 1: Get the Session ID<\/strong><\/h3>\n<p>To kill any screen session, to attach or detach the screens on Linux its ID is required, so in that case the screen command can be used with the ls flag to list down all the running screen sessions:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">screen<\/span> <span class=\"re5\">-ls<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"852\" height=\"240\" class=\"wp-image-23187\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-4.png 852w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-4-300x85.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-4-768x216.png 768w\" sizes=\"auto, (max-width: 852px) 100vw, 852px\" \/><\/p>\n<h3><strong>Step 2: Kill the Screen Session using the screen Command <\/strong><\/h3>\n<p>Once the session ID is known, execute the below-given syntax that uses the screen command to kill the screen session on Linux:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">screen<\/span> <span class=\"re5\">-X<\/span> <span class=\"re5\">-S<\/span> <span class=\"br0\">&#91;<\/span>session ID<span class=\"br0\">&#93;<\/span> quit<\/div><\/div>\n<p>Here<\/p>\n<ul>\n<li>The X flag is used to execute the screen command for the specified session ID,<\/li>\n<li>The S flag specifies the session by the given ID.<\/li>\n<\/ul>\n<p>So now, using the above-given syntax to kill the screen session, here the session ID for screen1 is 2959:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">screen<\/span> <span class=\"re5\">-X<\/span> <span class=\"re5\">-S<\/span> <span class=\"nu0\">2959<\/span> quit<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"262\" class=\"wp-image-23188\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-5.png 872w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-5-300x90.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-5-768x231.png 768w\" sizes=\"auto, (max-width: 872px) 100vw, 872px\" \/><\/p>\n<h3><strong>Killing a Screen Session Without Attaching and Using its Name <\/strong><\/h3>\n<p>If the screen session is not attached, then after the listing of the screen sessions execute the below syntax:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">screen<\/span> <span class=\"re5\">-S<\/span> <span class=\"sy0\">&lt;<\/span>screen-name<span class=\"sy0\">&gt;<\/span> <span class=\"re5\">-X<\/span> quit<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"855\" height=\"485\" class=\"wp-image-23189\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/a-screenshot-of-a-computer-description-automatica.png\" alt=\"A screenshot of a computer Description automatically generated\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/a-screenshot-of-a-computer-description-automatica.png 855w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/a-screenshot-of-a-computer-description-automatica-300x170.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/a-screenshot-of-a-computer-description-automatica-768x436.png 768w\" sizes=\"auto, (max-width: 855px) 100vw, 855px\" \/><\/p>\n<p><strong>Note:<\/strong> To use the screen command, you have to install it first so for that execute:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> apt <span class=\"kw2\">install<\/span> <span class=\"kw2\">screen<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"856\" height=\"280\" class=\"wp-image-23190\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-7.png 856w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-7-300x98.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-7-768x251.png 768w\" sizes=\"auto, (max-width: 856px) 100vw, 856px\" \/><\/p>\n<h2><a id=\"post-23182-v9tcafvv3nw\"><\/a><strong>Method 3: Through pkill Command <\/strong><\/h2>\n<p>The pkill is another utility that can be used to terminate or kill the screen session on Linux using the session\u2019s full or partial name. It is quite similar to the kill command, here are two steps that are to be followed to kill the screen session using pkill:<\/p>\n<h3><strong>Step 1: Get the Session ID<\/strong><\/h3>\n<p>To kill any screen session, to attach or detach the screens on Linux its ID is required, so in that case the screen command can be used with the ls flag to list down all the running screen sessions:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">screen<\/span> <span class=\"re5\">-ls<\/span><\/div><\/div>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"856\" height=\"250\" class=\"wp-image-23191\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-8.png 856w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-8-300x88.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-8-768x224.png 768w\" sizes=\"auto, (max-width: 856px) 100vw, 856px\" \/><\/strong><\/p>\n<h3><strong>Step 2: Kill the Screen Session Using pkill Command<\/strong><\/h3>\n<p>As in the previous step we listed the screen sessions that displayed their names as well, so now use the pkill command along with the session ID to kill the respective screen session:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">pkill <span class=\"re5\">-s<\/span> <span class=\"sy0\">&lt;<\/span>sessionID<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>So, now for demonstration, I have terminated the screen session having an ID 5140 by using the above syntax:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">pkill <span class=\"re5\">-s<\/span> <span class=\"nu0\">5140<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"856\" height=\"317\" class=\"wp-image-23192\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-9.png 856w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-9-300x111.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-9-768x284.png 768w\" sizes=\"auto, (max-width: 856px) 100vw, 856px\" \/><\/p>\n<h2><a id=\"post-23182-uiwfm4cjsspg\"><\/a><strong>Method 4: Attach Screen and Exit<\/strong><\/h2>\n<p>On Linux, the screen session can be terminated by just exciting it and for that first the screen session should be attached. So here are the two steps that you need to follow in this regard:<\/p>\n<h3><strong>Step 1: Attach the Screen Session <\/strong><\/h3>\n<p>To attach the screen session just use the r flag with the screen command and the screen name, to get the list of attached and detached screens use the ls command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">screen<\/span> <span class=\"re5\">-r<\/span> <span class=\"sy0\">&lt;<\/span>screen-session-name<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"862\" height=\"272\" class=\"wp-image-23193\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-10.png 862w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-10-300x95.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-10-768x242.png 768w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" \/><\/strong><\/p>\n<h3><strong>Step 2: Exit the Screen Session <\/strong><\/h3>\n<p>Once you have attached the screen session, just execute the exit command and the screen will be terminated:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">exit<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"904\" height=\"595\" class=\"wp-image-23194\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-11.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-11.png 904w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-11-300x197.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/11\/word-image-23182-11-768x505.png 768w\" sizes=\"auto, (max-width: 904px) 100vw, 904px\" \/><\/p>\n<h2><strong>Conclusion <\/strong><\/h2>\n<p>Screen sessions in Linux provide users with the privilege of multitasking, which saves a lot of time while executing the commands. When a screen session is closed, it is most likely to still run in the background, which can consume unnecessary resources. To kill a screen session on Linux there are four ways: using pkill command, screen command, kill command, killall command, and exiting the attached screen.<\/p>","protected":false},"excerpt":{"rendered":"<p>To kill a screen session on Linux there are four ways: using pkill command, the screen command, kill command and exiting the attached screen. <\/p>","protected":false},"author":110,"featured_media":23183,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-23182","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/23182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=23182"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/23182\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/23183"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=23182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=23182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=23182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}