{"id":940,"date":"2024-07-31T05:42:00","date_gmt":"2024-07-31T05:42:00","guid":{"rendered":"https:\/\/linux.thingsomething.com\/?p=940"},"modified":"2024-07-31T05:42:00","modified_gmt":"2024-07-31T05:42:00","slug":"how-to-list-all-the-files-opened-by-a-particular-pid","status":"publish","type":"post","link":"https:\/\/linux.thingsomething.com\/index.php\/2024\/07\/31\/how-to-list-all-the-files-opened-by-a-particular-pid\/","title":{"rendered":"how to list all the files opened by a particular PID ?"},"content":{"rendered":"\n<p>To list all the files opened by a particular process identified by its Process ID (PID), you can use the <code>lsof<\/code> command or look into the <code>\/proc<\/code> filesystem on Unix-like systems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using <code>lsof<\/code><\/h3>\n\n\n\n<p>The <code>lsof<\/code> (List Open Files) command is a utility that provides detailed information about files opened by processes. To list all the files opened by a specific PID, you can use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>lsof -p &lt;PID&gt;<\/code><\/pre>\n\n\n\n<p>Replace <code>&lt;PID&gt;<\/code> with the actual process ID.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using <code>\/proc<\/code> Filesystem<\/h3>\n\n\n\n<p>You can also find the information in the <code>\/proc<\/code> directory, which contains information about processes.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Navigate to the directory for the specific PID:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   cd \/proc\/&lt;PID&gt;\/fd<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>List the files:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   ls -l<\/code><\/pre>\n\n\n\n<p>Each entry in this directory is a symbolic link to an open file descriptor for the process. The links will show the files that are opened by the process with the specified PID.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<p>If the PID is <code>1234<\/code>, you can use either of the following methods:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using <code>lsof<\/code>:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  lsof -p 1234<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using <code>\/proc<\/code> filesystem:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  cd \/proc\/1234\/fd\n  ls -l<\/code><\/pre>\n\n\n\n<p>Both methods will provide you with a list of files opened by the process with PID <code>1234<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To list all the files opened by a particular process identified by its Process ID (PID), you can use the lsof command or look into &hellip; <span class=\"ml-btn\"><a href=\"https:\/\/linux.thingsomething.com\/index.php\/2024\/07\/31\/how-to-list-all-the-files-opened-by-a-particular-pid\/\" class=\"more-link\">Read More<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[284],"tags":[286,285,287],"class_list":["post-940","post","type-post","status-publish","format-standard","hentry","category-linux-interview","tag-linux-ninterview","tag-lsof","tag-pid"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/linux.thingsomething.com\/index.php\/wp-json\/wp\/v2\/posts\/940"}],"collection":[{"href":"https:\/\/linux.thingsomething.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linux.thingsomething.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linux.thingsomething.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linux.thingsomething.com\/index.php\/wp-json\/wp\/v2\/comments?post=940"}],"version-history":[{"count":1,"href":"https:\/\/linux.thingsomething.com\/index.php\/wp-json\/wp\/v2\/posts\/940\/revisions"}],"predecessor-version":[{"id":941,"href":"https:\/\/linux.thingsomething.com\/index.php\/wp-json\/wp\/v2\/posts\/940\/revisions\/941"}],"wp:attachment":[{"href":"https:\/\/linux.thingsomething.com\/index.php\/wp-json\/wp\/v2\/media?parent=940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linux.thingsomething.com\/index.php\/wp-json\/wp\/v2\/categories?post=940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linux.thingsomething.com\/index.php\/wp-json\/wp\/v2\/tags?post=940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}