ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to script out a list of applications to show their process IDs and where they're running from.
E.g.
2504 /usr/bin/bash
2605 /usr/sbin/bash
I'd like to do something like:
ps -C name -o pid cmd
but the -o parameter can only take one argument. Is there any way to do this in one command or would I have to get a list of matching PIDs and iterate through them to get the locations? While doable it's a lot more complex.
I tend to do stuff brute force a lot, and I'm not a big "set iterator", but will do that when it needs to be done.
How are you obtaining your list of PID and CMD's? Put them into a set and you can write a bash for loop to iterate on that set.
Not exact, but the syntax is something like, "for A in $SET", suggest you look up the exact syntax if you choose to do this.
As far as how to construct the set, which is called an associative array, if you do a find command or assign the output of some other type of search, it will create the associative array, what I call a set.
I assumed with the OP that the -o option takes just one parameter.
Obviously, NevemTeve made me wrong.
His solution is more elegant and shorter than mine.
You will just need to loop over application to substitute for name.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.