{"id":1946,"date":"2020-01-14T18:02:41","date_gmt":"2020-01-14T10:02:41","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=1946"},"modified":"2020-05-12T14:12:47","modified_gmt":"2020-05-12T06:12:47","slug":"how-to-terminate-screen-terminal-sessions-cleanly-on-macos","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-to-terminate-screen-terminal-sessions-cleanly-on-macos\/","title":{"rendered":"How to terminate screen terminal sessions cleanly on macOS"},"content":{"rendered":"<p>So how do you communicate with a serial device that is connected to your Mac?<\/p>\n<p>In this situation, you can use the screen command on your Mac to do so.<\/p>\n<p>After you terminate the serial session with Ctrl+A+D, you may find that the serial device is still being hogged by the screen command.<\/p>\n<p>When you try to access the device again, you may encounter a <strong>Resource busy<\/strong> error message. <\/p>\n<p>For example, after I detached my screen terminal from <strong>\/dev\/cu.SLAB_USBtoUART<\/strong>, I will get the following message if I try to connect to the same device again:<br \/>\n<strong><br \/>\nCannot open line '\/dev\/cu.SLAB_USBtoUART' for R\/W: Resource busy<br \/>\n<\/strong><\/p>\n<p>Given these points, this post shows how we can terminate screen terminal sessions cleanly on macOS.<\/p>\n<h2>Steps to terminate screen terminal sessions cleanly on macOS<\/h2>\n<p>In order to create the situation of resource hogging, let's connect your serial device with the screen command. For example, I may connect to my ESPx device with the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nscreen -port \/dev\/cu.SLAB_USBtoUART 115200\r\n<\/pre>\n<p>After doing so, detach the session by pressing <strong>Ctrl+A+D<\/strong>.<\/p>\n<p>When you do so, the serial device is still being locked by the screen command. <\/p>\n<p>Given that, let's list the screens that are being locked with the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nscreen -list\r\n<\/pre>\n<p>After the command completes, you should see something like this the following as an output:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nThere is a screen on:\r\n\t10184.ttys001.ZZZM56582454A\t(Detached)\r\n1 Socket in \/var\/folders\/vs\/lx78cw0x7m921p6qdmw9h4xm0000gr\/T\/.screen.\r\n<\/pre>\n<p>In order to terminate the screen terminal cleanly, run the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nscreen -X -S 10184 quit\r\n<\/pre>\n<p>After the command completes, you can run the screen command to verify if the session had been terminated:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nscreen -list\r\n<\/pre>\n<p>When the previous terminal session had been terminated successfully, you should see the following output:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nNo Sockets found in \/var\/folders\/vs\/lx78cw0x7m921p6qdmw9h4xm0000gr\/T\/.screen.\r\n<\/pre>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-vo\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-vo&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-vo&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1946&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>So how do you communicate with a serial device that is connected to your Mac?<\/p>\n<p>In this situation, you can use the screen command on your Mac to do so.<\/p>\n<p>After you terminate the serial session with Ctrl+A+D, you may find that the serial device is still being hogged by the screen command.<\/p>\n<p>When you try to access the device again, you may encounter a <strong>Resource busy<\/strong> error message. <\/p>\n<p>For example, after I detached my screen terminal from <strong>\/dev\/cu.SLAB_USBtoUART<\/strong>, I will get the following message if I try to connect to the same device again:<br \/>\n<strong><br \/>\nCannot open line &#8216;\/dev\/cu.SLAB_USBtoUART&#8217; for R\/W: Resource busy<br \/>\n<\/strong><\/p>\n<p>Given these points, this post shows how we can terminate screen terminal sessions cleanly on macOS.<\/p>\n","protected":false},"author":1,"featured_media":1947,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[650,717],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/mac-finder-icon.jpg","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-vo","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/1946"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=1946"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/1946\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1947"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=1946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=1946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=1946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}