I have a need, for a python script I'm creating, to first get just the PID of a process (based on its name) and then to get from that process, usings its PID, its time duration, which, from the printout below, would be "00:00:00"
root 5686 1 0 Sep23 ? 00:00:00 process-name
I am using this to get just the PID, by the process's name:
ps -ef |grep `whoami`| grep process-name | cut -c10-15
So, this works fine and I am assuming that the cut parameters (-c10-15) would work universally as the placement of the PID shouldn't change (I just got this from a snippet I found)
However, when I try to do something similar to get just the TIME value, such as this it returns it differently
ps -f 5686
returns:
root 5686 1 0 Sep23 ? S 0:00 /path/to/process
So when I try a cut, as below, I don't think it would work properly as I'm not sure the spacing on this return is consistent and also its showing the time value differently than before (not the original "00:00:00" style of printout.
ps -f 5686 | cut -c40-47
I'm using this in my python script to record the PID of a specific process type (by name) so that I can later shut down that instance of the progra when needed. Any advice on what I can do to correct my approach is appreciated