{"id":5311,"date":"2014-03-30T20:38:51","date_gmt":"2014-03-30T20:38:51","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-do-i-find-threads-that-belong-to-the-same-process-in-linux-collection-of-common-programming-errors\/"},"modified":"2014-03-30T20:38:51","modified_gmt":"2014-03-30T20:38:51","slug":"how-do-i-find-threads-that-belong-to-the-same-process-in-linux-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-do-i-find-threads-that-belong-to-the-same-process-in-linux-collection-of-common-programming-errors\/","title":{"rendered":"How do I find threads that belong to the same process in Linux-Collection of common programming errors"},"content":{"rendered":"<p>Actually, you don&#8217;t need <code>task_struct<\/code> at all.<\/p>\n<p>See <strong>my gist<\/strong> for a example code on printing the threads of a process with a given pid.<\/p>\n<p><strong>Reference<\/strong><\/p>\n<p>Type <code>man proc<\/code> at the command line (online version), and find the entry for <strong><code>\/proc\/[pid]\/task<\/code><\/strong>.<\/p>\n<p>Quoting from the man page:<\/p>\n<blockquote>\n<p>This is a directory that contains one subdirectory for each thread in the process. The name of each subdirectory is the numerical thread ID ([tid]) of the thread.<\/p>\n<\/blockquote>\n<p>Note that one of the subdirectories in <code>\/proc\/[pid]\/task<\/code> is whatever <code>[pid]<\/code> is (the pid of the program you&#8217;re inspecting).<\/p>\n<p>You can then gather other information using the pseudo-files in the directory <code>\/proc\/[pid]\/task\/[tid]<\/code> for each thread pid <code>[tid]<\/code>.<\/p>\n<p><strong>Without C Code<\/strong><\/p>\n<p><code>ps -mo THREAD -p<\/code> should work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Actually, you don&#8217;t need task_struct at all. See my gist for a example code on printing the threads of a process with a given pid. Reference Type man proc at the command line (online version), and find the entry for \/proc\/[pid]\/task. Quoting from the man page: This is a directory that contains one subdirectory for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5311","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5311"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5311\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}