{"id":346,"date":"2017-07-28T11:05:20","date_gmt":"2017-07-28T15:05:20","guid":{"rendered":"https:\/\/carleton.ca\/rcs\/?page_id=346"},"modified":"2021-08-06T07:18:54","modified_gmt":"2021-08-06T11:18:54","slug":"background-queue-of-jobs","status":"publish","type":"page","link":"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/","title":{"rendered":"Background queue of jobs"},"content":{"rendered":"<h2>Overview<\/h2>\n<p>Task Spooler (<strong>tsp<\/strong>) is not installed on every Linux server. However, we mention it here because if it happens to be available, it is a straightforward way to run many jobs.<\/p>\n<p>Task Spooler is a type of job queuing software. There are many more complicated job queueing software packages. Task Spooler is a particularly simple tool. It only runs on one server for one user.<\/p>\n<p>The <strong>tsp<\/strong> command will run a job in the background; this lets you run other commands while <strong>tsp<\/strong> is busy running your program. The <strong>tsp<\/strong> command will even keep running your jobs after you logout or disconnect from the server.<\/p>\n<p>In its normal setup, only one job will run with <strong>tsp<\/strong> at a time.\u00a0 Once the first job finishes, <strong>tsp<\/strong> will automatically start the next job. This list of waiting jobs is called <em>queuing<\/em>, and is analogous to the lineup at a grocery store.<\/p>\n<p>Let&#8217;s start taking a more concrete look at how to use the tsp command.<\/p>\n<h2>Running Jobs<\/h2>\n<p>Just put <strong>tsp<\/strong> in front of the command you want to run. Note that <strong>tsp<\/strong> can only directly run a single command, but itself does not handle the special functionality of the Unix shell. So for example if you use a command containing pipes or output redirects, then it is easiest to put those shell commands into a file. This file is called a shell script, but is out of the scope of our current discussion.<\/p>\n<p>Let&#8217;s run a fictitious program called `run_simulation` using <strong>tsp<\/strong>:<\/p>\n<blockquote>\n<pre><strong>tsp .\/run_simulation -t 10\r\ntsp .\/run_simulation -t 3\r\ntsp .\/run_simulation -t 20\r\ntsp<\/strong>\r\nID   State      Output               E-Level  Times(r\/u\/s)   Command [run=1\/1]\r\n0    running    \/tmp\/ts-out.Smoz2i                           .\/run_simulation -t 10\r\n1    queued     (file)                                       .\/run_simulation -t 3\r\n2    queued     (file)                                       .\/run_simulation -t 20<\/pre>\n<\/blockquote>\n<p>We have queued up 3 jobs, each running a <strong>run_simulation<\/strong>. We&#8217;ll move on now to ways of managing jobs and getting output.<\/p>\n<h2>Listing Jobs<\/h2>\n<p>You can view your list of tsp jobs:<\/p>\n<blockquote>\n<pre><strong>tsp<\/strong>\r\nID   State      Output               E-Level  Times(r\/u\/s)   Command [run=1\/1]\r\n1    running    \/tmp\/ts-out.IiCgZe                           .\/run_simulation -t 10\r\n2    queued     (file)                                       .\/run_simulation -t 10\r\n0    finished   \/tmp\/ts-out.QUFZ40   0        2.00\/0.00\/0.00 .\/run_simulation -t 2<\/pre>\n<\/blockquote>\n<p>The number from the ID column will be used to refer to particular jobs. The State column tells you the progress tsp is making in your job queue.<\/p>\n<p>One important caveat &#8211; the list of jobs is kept in memory.\u00a0 So if your server reboots then you will lose any existing jobs.\u00a0 So it is important to collect any needed information about completed jobs.<\/p>\n<h2>Inspecting Jobs<\/h2>\n<p>Let&#8217;s assume you have some finished <strong>tsp<\/strong> jobs that look like this:<\/p>\n<blockquote>\n<pre><strong>tsp<\/strong>\r\nID   State      Output               E-Level  Times(r\/u\/s)   Command [run=1\/1]\r\n0    finished   \/tmp\/ts-out.Smoz2i   0        10.04\/0.00\/0.00 .\/run_simulation -t 10\r\n1    finished   \/tmp\/ts-out.1UDMiN   0        3.02\/0.00\/0.00  .\/run_simulation -t 3\r\n2    finished   \/tmp\/ts-out.twnIHU   0        20.11\/0.00\/0.00 .\/run_simulation -t 20<\/pre>\n<\/blockquote>\n<p>Note that tsp gives each job an ID. \u00a0You can see the output of job with ID 1:<\/p>\n<blockquote><p><strong>tsp -c 1<\/strong><br \/>\nThis is sample output from<br \/>\na program!<\/p><\/blockquote>\n<p>And to see detailed information about the job:<\/p>\n<blockquote>\n<pre><strong>tsp -i 1<\/strong>\r\nExit status: died with exit code 0\r\nCommand: .\/run_simulation -t 3\r\nSlots required: 1\r\nEnqueue time: Fri Jul 14 10:45:28 2017\r\nStart time: Fri Jul 14 10:45:38 2017\r\nEnd time: Fri Jul 14 10:45:41 2017\r\nTime run: 3.021296s<\/pre>\n<\/blockquote>\n<h2>Cleaning up Jobs<\/h2>\n<p>To remove a queued job with ID 2:<\/p>\n<blockquote>\n<pre><strong>tsp -r 2<\/strong><\/pre>\n<\/blockquote>\n<p>To clear the list of all finished jobs:<\/p>\n<blockquote>\n<pre><strong>tsp -C<\/strong><\/pre>\n<\/blockquote>\n<p>To kill (stop) a running job with ID 2:<\/p>\n<blockquote>\n<pre><strong>tsp -k 2<\/strong><\/pre>\n<\/blockquote>\n<h2>Concurrent Jobs<\/h2>\n<p>The tsp command can run more than one job at the same time.\u00a0 In the\u00a0<strong>tsp<\/strong> queue list, the header indicates how many jobs are running, and how many are allowed to run.<\/p>\n<p>However, if your job already uses multiple cores or if your job uses most of the server&#8217;s RAM, then you should not run multiple tsp jobs at the same time.<\/p>\n<p>For example, to run 4 jobs at the same time:<\/p>\n<blockquote>\n<pre><strong>tsp<\/strong>\r\nID   State      Output               E-Level  Times(r\/u\/s)   Command [<strong>run=0\/1<\/strong>]\r\n\r\n<strong>tsp -S 4<\/strong>\r\n\r\n<strong>tsp<\/strong>\r\nID   State      Output               E-Level  Times(r\/u\/s)   Command [<strong>run=0\/4<\/strong>]<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Overview Task Spooler (tsp) is not installed on every Linux server. However, we mention it here because if it happens to be available, it is a straightforward way to run many jobs. Task Spooler is a type of job queuing software. There are many more complicated job queueing software packages. Task Spooler is a particularly [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"parent":96,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_mi_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Background queue of jobs - Research Computing Services<\/title>\n<meta name=\"description\" content=\"Overview Task Spooler (tsp) is not installed on every Linux server. However, we mention it here because if it happens to be available, it is a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/\",\"url\":\"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/\",\"name\":\"Background queue of jobs - Research Computing Services\",\"isPartOf\":{\"@id\":\"https:\/\/carleton.ca\/rcs\/#website\"},\"datePublished\":\"2017-07-28T15:05:20+00:00\",\"dateModified\":\"2021-08-06T11:18:54+00:00\",\"description\":\"Overview Task Spooler (tsp) is not installed on every Linux server. However, we mention it here because if it happens to be available, it is a\",\"breadcrumb\":{\"@id\":\"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/carleton.ca\/rcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Research Computing and Development Cloud (RCDC)\",\"item\":\"https:\/\/carleton.ca\/rcs\/rcdc\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Background queue of jobs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/carleton.ca\/rcs\/#website\",\"url\":\"https:\/\/carleton.ca\/rcs\/\",\"name\":\"Research Computing Services\",\"description\":\"Carleton University\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/carleton.ca\/rcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Background queue of jobs - Research Computing Services","description":"Overview Task Spooler (tsp) is not installed on every Linux server. However, we mention it here because if it happens to be available, it is a","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/","url":"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/","name":"Background queue of jobs - Research Computing Services","isPartOf":{"@id":"https:\/\/carleton.ca\/rcs\/#website"},"datePublished":"2017-07-28T15:05:20+00:00","dateModified":"2021-08-06T11:18:54+00:00","description":"Overview Task Spooler (tsp) is not installed on every Linux server. However, we mention it here because if it happens to be available, it is a","breadcrumb":{"@id":"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/carleton.ca\/rcs\/rcdc\/background-queue-of-jobs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/carleton.ca\/rcs\/"},{"@type":"ListItem","position":2,"name":"Research Computing and Development Cloud (RCDC)","item":"https:\/\/carleton.ca\/rcs\/rcdc\/"},{"@type":"ListItem","position":3,"name":"Background queue of jobs"}]},{"@type":"WebSite","@id":"https:\/\/carleton.ca\/rcs\/#website","url":"https:\/\/carleton.ca\/rcs\/","name":"Research Computing Services","description":"Carleton University","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/carleton.ca\/rcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"}]}},"acf":{"banner_image_type":"none","banner_button":"no"},"_links":{"self":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/346"}],"collection":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/comments?post=346"}],"version-history":[{"count":4,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/346\/revisions"}],"predecessor-version":[{"id":785,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/346\/revisions\/785"}],"up":[{"embeddable":true,"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/pages\/96"}],"wp:attachment":[{"href":"https:\/\/carleton.ca\/rcs\/wp-json\/wp\/v2\/media?parent=346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}