So I'm trying to find the PID of any process which has the word "control" in it. I'm in ruby on linux. This is the basic code so far
`ps aux | grep control`
If I run that in ruby, all the distinct lines that would come back when run in linux, get concatenated into one long string. How can I have ruby read the results in as a list, instead of one long string?
You can split it on the newline characters like so:
lines = (`ps aux | grep control`).split(/\n/)
With that done you can iterate over them, select things out using a regex, etc..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With