Allow to use the process name to watch process (-d) #95
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ivarch/pv#95
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
By using
pidof -s [processname]internally, pv could work without having to first manually use pidof.Maybe a different argument name should be used instead of
-d.There would still be room for improvement in case of multiple PIDs for the same process name, but for many use cases it would make it much easier to use.
That sounds reasonable, changing
-dto accept a non-numeric argument, which will cause it to use the first process with that name.I'm uneasy about actually spawning "
pidof" so may try to implement the lookup inside PV.To find a matching process we could look at:
I would suggest we should look for matches in this order, and choose the first match, ignoring all zombie processes:
Just calling "
pidof -s" would be simpler. I don't like the idea of doing that because we're then making PV spawn a subprocess and it has to do that safely, run the real "pidof" from the right path, and capture the output without making a mess, and these all seem like they will be tricky to do right. We're then also stuck with the first match, with no control over the search order.On the other hand, to do it without "
pidof" will make PV a bit more complicated. How much more complicated I don't know, I need to go look at the source for "pidof" to see how it finds out things like the controlling terminal of a process.Can't tell if I'm fussing over nothing and making it more than it needs to be - thoughts welcome.
I would suggest checking each value returned by
pidofand stopping at the first one that shows any kind of progress (non zero speed).A more complicated way would be to list all processes with progress (showing the interesting line(s)) and ask the user which one to watch.
If we look for progress, that means a delay in starting up, but I think it won't matter very much.
If we use
pgrepinstead ofpidof, then it will work on BSD as well as Linux. Can you see any problems with making this change?One thing I've noticed is that
pgrep -x firefoxwill only return the main process whereaspidof firefoxwill return the spawn processes (which aren't named "firefox") too.On the other hand,
pidof kthreadddoesn't return anything, andpgrep kworkerreturns of course all kworkers (wether that's a good thing or not though is another question).pv could also try with pidof and use pgrep otherwise.
OK so PV should try to run "pidof " and then, if pidof can't execute at all (command not found), run "pgrep " instead. It should read back the result, and use it as a list of process IDs to look for activity in. The first process in the list that shows movement on a file descriptor will then be the one it watches.
(Note to self: pidof separates the PIDs in its output with a space, while pgrep uses a newline; although pidof provides a "-d" option to change the separator, that's not available everywhere)
I've grouped this issue along with several others under a general milestone of "rewrite of watchfd", since to take this forward the file descriptor watching code needs restructuring. In particular for this issue I need to separate out the watched fd information from the overall state, so we can look at several PIDs for a short while to see which one has activity first, and then drop it all and start a regular watchfd loop on one selected PID. The whole milestone looks like this at the moment:
Getting those done together will allow several other issues to be dealt with too.
The simpler approach of just calling
pgrephas been taken, sincepvcan now watch multiple processes (#12). The syntax is "--watchfd =NAME", where NAME is the process name - this is passed topgrepand the resultant list of PIDs is watched.Closing as this is now in version 1.9.42.