TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

So, what can you do with a process ID?

90 pointsby gcmeplzover 2 years ago

12 comments

ghostpepperover 2 years ago
My go-to incantation is `ps ajxf`, (truncated and edited) sample output below<p><pre><code> PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 0 1 1 1 ? -1 Ss 0 0:57 &#x2F;sbin&#x2F;init splash 1 978 978 978 ? -1 Ss 0 0:00 &#x2F;usr&#x2F;sbin&#x2F;sshd -D 978 11441 11441 11441 ? -1 Ss 0 0:00 \_ sshd: ghostpepper [priv] 11441 11445 11441 11441 ? -1 S 1000 0:00 \_ sshd: ghostpepper@pts&#x2F;4 11445 11446 11446 11446 pts&#x2F;4 11641 Ss 1000 0:00 \_ -bash 11446 11641 11641 11446 pts&#x2F;4 11641 R+ 1000 0:00 \_ ps ajxf </code></pre> Another thing some might not know is that kill (the command &#x2F; syscall) can send a lot of other signals than KILL (the signal). Not all processes know how to gracefully handle them, so you need to be careful, but for example a lot of daemons can catch SIGHUP and re-load their config file from disk.
kmstoutover 2 years ago
<p><pre><code> Way hay we&#x27;re out of memory Way hay our disk is thrashing Way hay I need more coffee Early in the morning! What can you do with a process ID What can you do with a process ID What can you do with a process ID Early in the morning? Send a SIGKILL to its process Send a SIGKILL to its process Send a SIGKILL to its process Early in the morning!</code></pre>
评论 #34030399 未加载
评论 #34029018 未加载
tdootover 2 years ago
Interesting there&#x27;s no mention of the <i>&#x2F;proc</i> filesystem (<a href="https:&#x2F;&#x2F;docs.kernel.org&#x2F;filesystems&#x2F;proc.html" rel="nofollow">https:&#x2F;&#x2F;docs.kernel.org&#x2F;filesystems&#x2F;proc.html</a>).<p><i>cat &#x2F;proc&#x2F;&lt;pid&gt;&#x2F;environ</i> would be a solid addition to this list.
评论 #34024442 未加载
评论 #34031717 未加载
yakubinover 2 years ago
On Linux one of my favourite tools to display metrics about a process in real time, such as cpu&#x2F;memory&#x2F;io utilisation, which can also be broken down per thread (with friendly thread names displayed if your application sets them), is pidstat from the sysstat package.
hsfzxjyover 2 years ago
And with strace -p pid you can somewhat &quot;spy&quot; on what a process is doing.
评论 #34028270 未加载
评论 #34022793 未加载
评论 #34029946 未加载
jasonhanselover 2 years ago
Annoyingly, what you <i>can&#x27;t</i> always do is use it to uniquely identify a process. After a process exits, its PID can be reused. On Linux this (by default) only happens after PID 32767 is assigned, but generally it&#x27;s implementation-defined. A rare edge case, of course, but it can have security implications.
cpuguy83over 2 years ago
On modern kernels you can do some really interesting things like &quot;pidfd_open&quot; and &quot;pidfd_getfd&quot; to get a duplicate file descriptor from the process referred to by the pidfd.
ktpsnsover 2 years ago
Another nice addition would have been debuggers such as gdb -p PID to hook into the running code, see for instance <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;2308653&#x2F;can-i-use-gdb-to-debug-a-running-process" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;2308653&#x2F;can-i-use-gdb-to...</a>
dezgegover 2 years ago
Could have written disclaimer in the &#x27;kill -HUP&#x27; example that they should be only sent when it is known that the destination process will handle it, as the default for most signals is to terminate the process.<p>Especially since every other example is non-destructive...
pletnesover 2 years ago
I know about some of these tricks. However, containers are popular and typically don’t have the tools installed, and you can’t necessarily sudo either. What do people replace these tricks with, in some cloud container or k8s pods?
评论 #34028494 未加载
daniel-sover 2 years ago
For a moment I thought the topic was about PID controllers. That would have been cool.<p>If the blogging gods take requests I just made one.
评论 #34021616 未加载
crossingTimeover 2 years ago
When I was a chemist we used photoionization detectors to detect VOCs in groundwater.