Is there a way in python to hijack the terminal stdin? Unix only solutions will do fine.
I'm currently writing a small wrapper around top
as I want to be able to monitor named processes, e.g. all running python instances. Basically I'm calling pgrep
to get process id's and then runs top
using the -p
option.
Overall this script have worked satisfactorily for a few years now (well with the caveat that top -p
only accepts 20 pid's...). However, I now would like adjust the script to update the call to top if new processes matching the name pattern are born. This also works relatively nicely, but... any options set interactively in top
gets lost every time I update the pid list but natural causes as I stop and restart top
. Therefore I would like to hijack the terminal stdin somehow to be able to backtrack what ever the settings are in affect so I can set them accordingly after updating the pid-list, or even halt updating if neccesary (e.g. if top is awaiting more instructions from the user).
Now perhaps what I'm trying to achieve is just silly and there are better ways to do it, if so I'd highly appreciate enlightenment
(oh. the tag ps
were used as the tag top
does not exists and I'm to new here to define new tags, after all the two utilities are related)
thanks \p