{"id":153,"date":"2024-02-28T02:08:58","date_gmt":"2024-02-27T17:08:58","guid":{"rendered":"https:\/\/blog.gerd.kr\/?p=153"},"modified":"2024-03-02T22:09:54","modified_gmt":"2024-03-02T13:09:54","slug":"truenas-%ec%97%90%ec%84%9c-pgrep-%ec%9c%bc%eb%a1%9c-pid-%ec%95%8c%ec%95%84%eb%82%b4%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/blog.gerd.kr\/?p=153","title":{"rendered":"TrueNAS \uc5d0\uc11c pgrep \uc73c\ub85c PID \uc54c\uc544\ub0b4\uae30"},"content":{"rendered":"\n<p>Calibre-Web \uc758 rc.d \uc2a4\ud06c\ub9bd\ud2b8\ub97c \uc791\uc131\ud558\uba74\uc11c, \ub0b4\uac00 \uc0ac\uc6a9\ud558\ub294 jupyter-lab \uc758 rc.d \uc2a4\ud06c\ub9bd\ud2b8\uac00 \ubb54\uac00 \uc880 \uc774\uc0c1\ud558\ub2e4\ub294 \uc0dd\uac01\uc774 \ub4e4\uc5c8\ub2e4. \uadf8\ub798\uc11c \ub2e4\uc2dc \ud655\uc778\ud574 \ubd24\ub294\ub370, \uc5ed\uc2dc\ub098&#8230; \ud504\ub85c\uc138\uc2a4 ID \ub97c \uc81c\ub300\ub85c \uace8\ub77c\ub0b4\uc9c8 \ubabb\ud558\uace0 \uc788\uc5c8\ub2e4. <\/p>\n\n\n\n<p>\ucc98\uc74c\uc5d0\ub294 user \uc640 command \ubcc0\uc218\uc5d0 \uc9c0\uc815\ud55c \uba85\ub839\uc73c\ub85c pid \ub97c \ucc3e\uc558\ub2e4. \uac01\uac01 -u \uc635\uc158\uacfc -f \uc635\uc158\uc774\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pgrep -u \"${user}\" -f \"${command}\"<\/code><\/pre>\n\n\n\n<p>\uc800\ub807\uac8c \ud558\uba74 \ud558\ub098\ub9cc \ub098\uc654\uace0, Jail \uc758 shell \uc5d0 \ub4e4\uc5b4\uac00\uc11c service status \ub97c \ud655\uc778\ud574\ub3c4 \ud558\ub098\ub9cc \ub098\uc640\uc11c \uc798 \ub418\ub294 \uc904 \uc54c\uc558\ub294\ub370&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shell &gt; service jupyter status\njupyter running with pid: 97074<\/code><\/pre>\n\n\n\n<p>\uc2dc\uac04\uc774 \uc880 \uc9c0\ub09c \ub2e4\uc74c\uc5d0 \uac80\uc0c9\ud558\uba74 \uc65c\uc778\uc9c0\ub294 \ubaa8\ub974\uaca0\ub294\ub370, root \uc5d0\uc11c \uc2e4\ud589\ud55c su \uba85\ub839\uc774 user \uacc4\uc815\uc5d0\uc11c \uc2e4\ud589\ud55c \uac83 \ucc98\ub7fc \ubc14\ub00c\uc5b4\uc11c \uc800 \uc870\uac74\uc73c\ub85c 2\uac1c\uac00 \ub098\uc628\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shell &gt; pgrep -l -u jupyter -f jupyter-lab\n97070 _su -c \/usr\/local\/bin\/jupyter-lab\n97074 \/usr\/local\/bin\/python3.9 \/usr\/local\/bin\/jupyter-lab<\/code><\/pre>\n\n\n\n<p>\uadf8\ub798\uc11c su \uba85\ub839\uc73c\ub85c \uc2e4\ud589\ud55c \ud504\ub85c\uc138\uc2a4\ub97c \uc885\ub8cc\ud558\uba74 \ub420\uac70\ub77c \uc0dd\uac01\ud588\ub294\ub370, python \uc73c\ub85c \uc2e4\ud589\ud55c jupyter-lab \uc740 \ub531 \ud574\ub2f9\ud558\ub294 pid \ub85c kill \uba85\ub839\uc744 \ub123\uc9c0 \uc54a\uc73c\uba74 \uc81c\ub300\ub85c \ud504\ub85c\uc138\uc2a4\uac00 \uc885\ub8cc\ub418\uc9c0 \uc54a\uc558\ub2e4. \uadf8\ub798\uc11c ${command} \ub300\uc2e0 &#8220;python3&#8221; \ub85c \uac80\uc0c9\ud588\ub294\ub370, \uc544\uae4c\uba69\ud0a4\ub85c \ucc98\uc74c\uc5d0\ub294 \ud55c \uac1c\ub9cc \uc798 \ub098\uc624\ub2e4\uac00 \uc2dc\uac04\uc774 \uc880 \uc9c0\ub098\uba74&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shell &gt; service jupyter status\njupyter running with pid: 97245\n97246\n97255\n97074<\/code><\/pre>\n\n\n\n<p>\uc774\ub807\uac8c \uc5ec\ub7ec \uac1c \ub098\uc628\ub2e4. -l \uc635\uc158\uc744 \ub123\uc5b4\uc11c \uc5b4\ub5a4 \ub188\ub4e4\uc778\uac00 \ucc3e\uc544\ubd24\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shell &gt; pgrep -l -u jupyter -f python3\n97245 \/usr\/local\/bin\/python3.9 -m ipykernel_launcher -f \/usr\/home\/jupyter\/.local\/share\/jupyter\/runtime\/kernel-09dfa3c9-f584-41ef-bcd5-526bacda24a6.json\n97246 \/usr\/local\/bin\/python3.9 -m ipykernel_launcher -f \/usr\/home\/jupyter\/.local\/share\/jupyter\/runtime\/kernel-d28efcc1-7365-4a5c-99d5-a372bfd0896c.json\n97255 \/usr\/local\/bin\/python3.9 -m pylsp\n97074 \/usr\/local\/bin\/python3.9 \/usr\/local\/bin\/jupyter-lab<\/code><\/pre>\n\n\n\n<p>\uc74c&#8230; su \ub294 \uc81c\ub300\ub85c \ud544\ud130\ub9c1\uc774 \ub418\uc5c8\ub294\ub370, \ub0b4\uac00 \uc791\uc5c5\uacf5\uac04\uc5d0 \uc0dd\uc131\ud55c \ub450 \uac1c\uc758 \uac00\uc0c1 \ucee4\ub110\uacfc \ud30c\uc774\uc36c \ub7ad\uadc0\uc9c0 \uc11c\ubc84 \ud504\ub85c\ud1a0\ucf5c\uc774 \ucd94\uac00\ub85c \ub098\uc628\ub2e4. man pgrep \ub97c \ub4a4\uc838\uc11c \uc77c\ub2e8 \ucc3e\uc740 \ud574\uacb0\ucc45\uc740 -o \uc635\uc158\uc744 \uc0ac\uc6a9\ud558\uc5ec \uac80\uc0c9 \ub41c \uac83 \uc911 \uac00\uc7a5 \uc624\ub798\ub41c \ud504\ub85c\uc138\uc2a4\uc758 pid \ub97c \uad6c\ud558\ub294 \uac83\uc774\uc9c0\ub9cc, \ub0b4 \uc0dd\uac01\uc5d4 -f \uc635\uc158\uc5d0\uc11c and \ub098 or \ub85c \uac80\uc0c9\uc870\uac74\uc744 \uc124\uc815\ud560 \uc218 \uc788\uc73c\uba74 \ub354 \ud655\uc2e4\ud558\uaca0\ub2e4 \uc2f6\uc5c8\ub2e4. \uadf8\ub798\uc11c \uadf8\ub0e5 \uc9ec\uc73c\ub85c &amp; \ub97c \ub123\uc5b4 \ubd24\ub294\ub370&#8230; \uc548\ub41c\ub2e4. or \uc870\uac74\uc740 \ube48\uce78 \ud639\uc740 | \uc73c\ub85c \ub418\ub294\ub370 &amp; \ub294 \ub3c4\ub2f9\ucdcc \ub418\uc9c8 \uc54a\ub294\ub2e4.<\/p>\n\n\n\n<p>\uadf8\ub798\uc11c ChatGPT \ud55c\ud14c \ubb3c\uc5b4\ubd24\ub294\ub370, \uc774 \ub140\uc11d\uc740 \uc774\ub7f0 \ub2f5\uc744 \uc92c\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pgrep -lf 'string 1' | grep 'string 2' | awk '{print $1}'<\/code><\/pre>\n\n\n\n<p>\uadf8\ub7ec\ub2c8\uae4c python3 \ub85c \uac80\uc0c9\ud574\uc11c 1\ucc28\ub85c \ub9ac\uc2a4\ud2b8\ub97c \ubf51\uace0, \uadf8\uac78 grep \uc744 \uc0ac\uc6a9\ud558\uc5ec jupyter-lab \uc73c\ub85c \uac70\ub978 \ub2e4\uc74c, awk \ub85c \ub9e8 \uc55e\uc758 pid \ub9cc \ubf51\uc544\ub0b4\ub77c\ub294 \uac70\uc600\ub2e4. \ucc98\uc74c \uc774 \ub2f5\uc744 \uc5bb\uc5c8\uc744 \ub54c \uc6b0\uc640~ \ud558\uba74\uc11c rc.d \uc2a4\ud06c\ub9bd\ud2b8\uc5d0 \ub123\uc5b4\ubd24\ub294\ub370, \ub9c8\uc9c0\ub9c9\uc758 $1 \uc744 rc.d \uc2a4\ud06c\ub9bd\ud2b8\uac00 \ubcc0\uc218\ub85c \ucde8\uae09\ud574\uc11c \uc790\uafb8 \uc5d0\ub7ec\uac00 \ub0ac\ub2e4. \ud558&#8230; \ub354 \uce90\ubb3c\uc5b4\ubcfc\uae4c \ud558\ub2e4\uac00 \uadf8\ub0e5 \uc801\ub2f9\ud788 \uac80\uc0c9\uc744 \ud588\ub294\ub370&#8230; <\/p>\n\n\n\n<p>\ub4dc\ub514\uc5b4 \uac78\ub824 \ub098\uc654\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt; pgrep -f \"otp.*place1\"<\/code><\/pre>\n\n\n\n<p>\ub72c\uae08\uc5c6\uac8c\ub3c4 <mark style=\"background-color:#ff8737\" class=\"has-inline-color has-black-color\"><strong>  .*<\/strong> <\/mark> \uc774 and \uc870\uac74\uc744 \uac70\ub294 \uad6c\ubd84\uc790\ub77c\uace0 \ud55c\ub2e4.<\/p>\n\n\n\n<p>\uc815\ud655\ud558\uac8c\ub294 \uc815\uaddc\uc2dd \ud45c\ud604\uc774\ub2e4. \u2019.\u2018 \uc740 \ub450 string \uc0ac\uc774\uc5d0 \uc5b4\ub5a4 \uae00\uc790\uac00 \ub4e4\uc5b4\uc640\ub3c4 \ub41c\ub2e4\ub294 \uac70\uace0, \u2019*\u2018 \uc740 \uadf8 \uae00\uc790\uc5d0 \uae38\uc774\uc81c\ud55c\uc744 \ub450\uc9c0 \uc54a\ub294\ub2e4\ub294 \uc758\ubbf8\ub2e4. \uadf8\ub7ec\ub2c8 \uc21c\uc11c\ub97c \ubc18\ub300\ub85c \ud558\uba74 \uac80\uc0c9\uc774 \uc548 \ub41c\ub2e4. \ub530\uc838\ubcf4\uba74 and \uc870\uac74\uc774\ub791\uc740 \uc758\ubbf8\uac00 \uc880 \ub2e4\ub974\ub2e4. -f \uc635\uc158\uc5d0 \uc815\uaddc\uc2dd\uc774 \ub41c\ub2e4\uace0 man \ud398\uc774\uc9c0\uc5d0\uc11c \ubd10 \ub193\uace0\ub294 \uadf8\ub0e5 and \ub9cc \ucc3e\uc544 \ud5e4\uba68\ub2e4. \ubbf8\uce5c&#8230; \u314b\u314b\u314b<\/p>\n\n\n\n<p>\uc5ec\ud2bc \uc2e4\ud589\ud574\ubcf4\uba74&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shell &gt; pgrep -u jupyter -f \"python3.*jupyter-lab\"\n97074<\/code><\/pre>\n\n\n\n<p>\ud558\ub098\ub9cc \uac78\ub824 \ub098\uc628\ub2e4. <\/p>\n\n\n\n<p>\uc774\uc81c\uc11c\uc57c \uac00\uc0c1 \ucee4\ub110\uc744 \uc5ec\ub7ec \uac1c \uc5f4\uc5b4\ub3c4 service stop, status, restart \uac00 \uc81c\ub300\ub85c \ub3d9\uc791\ud55c\ub2e4. \ud6c4&#8230; \ub098\uc911\uc5d0 \ub2e4\uc2dc \uc0bd\uc9c8\ud558\uc9c0 \ub9d0\ub77c\uace0 \uc218\uc815\ud55c Jupyter \uc758 rc.d \uc2a4\ud06c\ub9bd\ud2b8\ub97c \uc801\uc5b4\ub454\ub2e4. \ub0b4\uac00 \ucc38\uace0\ud55c \uc6d0\ubcf8\uc740 \/var\/run\/ \ud3f4\ub354\uc5d0 pid \ud30c\uc77c\uc744 \uc0dd\uc131\ud574\uc11c \uadf8\uac78\ub85c pid \ub97c \uac00\uc838\uc624\ub294 \uc2dd\uc774\uc5c8\ub294\ub370, \uc544\ubb34\ub9ac \ud574\ub3c4 pid \ud30c\uc77c\uc774 \uc81c\ub300\ub85c \uc0dd\uc131\ub418\uc9c0 \uc54a\uc558\ub2e4. \uadf8\ub798\uc11c \uc774 \uc0bd\uc9c8\uc744&#8230;T^T<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\n#\n# PROVIDE: jupyter\n# REQUIRE: LOGIN\n#\n# Add the following lines to \/etc\/rc.conf to enable jupyter notebook server\n#\n#\n# jupyter_enable (bool): Set to \"NO\" by default,\n#                         Set it to \"YES\" to enable jupyter notebook server\n\n. \/etc\/rc.subr\n\nname=jupyter\ncommand=\/usr\/local\/bin\/jupyter-lab\nrcvar=jupyter_enable\n\nload_rc_config $name\n\njupyter_enable=\"${jupyter_enable-\"NO\"}\"\njupyter_user=\"${jupyter_user-\"jupyter\"}\"\n\nexport HOME=\/home\/jupyter\n\nstart_cmd=\"su ${jupyter_user} -c '${command}' &amp;\"\nstop_cmd=\"${name}_stop\"\nstatus_cmd=\"${name}_status\"\n\njupyter_stop()\n{\n    <strong>jupyter_pid=$(pgrep -u \"${jupyter_user}\" -f <mark style=\"background-color:#ff8737\" class=\"has-inline-color\">python3.*\"${command}\"<\/mark>)<\/strong>\n    echo \"Stopping ${name}.\"\n    kill -s TERM \"${jupyter_pid}\"\n}\n\njupyter_status()python3.*\"${command}\"\n{\n    <strong>jupyter_pid=$(pgrep -u \"${jupyter_user}\" -f <mark style=\"background-color:#ff8737\" class=\"has-inline-color\">python3.*\"${command}\"<\/mark>)<\/strong>\n    if &#91; -n \"${jupyter_pid}\" ]\n    then\n        echo \"${name} running with pid: $jupyter_pid\"\n    else\n        echo \"${name} not running? (pid not found)\"\n    fi\n}\n\ncommand_args=\" &gt;\/dev\/null 2&gt;&amp;1 &amp;\"\n\nload_rc_config $name\nrun_rc_command \"$1\"\n<\/code><\/pre>\n\n\n\n<p>&#8211;\ucc38\uace0 \uc0ac\uc774\ud2b8&#8211;<\/p>\n\n\n\n<p><a href=\"https:\/\/serverfault.com\/questions\/985824\/pgrep-search-multiple-words\">https:\/\/serverfault.com\/questions\/985824\/pgrep-search-multiple-words<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/58527655\/pgrep-multiple-process-names\">https:\/\/stackoverflow.com\/questions\/58527655\/pgrep-multiple-process-names<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Calibre-Web \uc758 rc.d \uc2a4\ud06c\ub9bd\ud2b8\ub97c \uc791\uc131\ud558\uba74\uc11c, \ub0b4\uac00 \uc0ac\uc6a9\ud558\ub294 jupyter-lab \uc758 rc.d \uc2a4\ud06c\ub9bd\ud2b8\uac00 \ubb54\uac00 \uc880 \uc774\uc0c1\ud558\ub2e4\ub294 \uc0dd\uac01\uc774 \ub4e4\uc5c8\ub2e4. \uadf8\ub798\uc11c \ub2e4\uc2dc \ud655\uc778\ud574 \ubd24\ub294\ub370, \uc5ed\uc2dc\ub098&#8230; \ud504\ub85c\uc138\uc2a4 ID \ub97c \uc81c\ub300\ub85c \uace8\ub77c\ub0b4\uc9c8 \ubabb\ud558\uace0 \uc788\uc5c8\ub2e4. \ucc98\uc74c\uc5d0\ub294 user \uc640 command \ubcc0\uc218\uc5d0 \uc9c0\uc815\ud55c \uba85\ub839\uc73c\ub85c pid \ub97c \ucc3e\uc558\ub2e4. \uac01\uac01 -u \uc635\uc158\uacfc -f \uc635\uc158\uc774\ub2e4. \uc800\ub807\uac8c \ud558\uba74 \ud558\ub098\ub9cc \ub098\uc654\uace0, Jail \uc758 shell \uc5d0 \ub4e4\uc5b4\uac00\uc11c service status \ub97c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[37,38,58,59,60,32,8],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-truenas","tag-jupyter","tag-jupyterlab","tag-pgrep","tag-pid","tag-python3","tag-rc-d","tag-truenas"],"_links":{"self":[{"href":"https:\/\/blog.gerd.kr\/index.php?rest_route=\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.gerd.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gerd.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gerd.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gerd.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=153"}],"version-history":[{"count":23,"href":"https:\/\/blog.gerd.kr\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":224,"href":"https:\/\/blog.gerd.kr\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions\/224"}],"wp:attachment":[{"href":"https:\/\/blog.gerd.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gerd.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gerd.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}