Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
By default 'nohup' logs to "~/nohup.out" so list open files: "lsof -w -n | awk '/nohup.out/ {print $2, "("$1")"}'", for amount remove the ", "("$1")"" part and add "|sort|uniq|wc -l".
By default 'nohup' logs to "~/nohup.out" so list open files: "lsof -w -n | awk '/nohup.out/ {print $2, "("$1")"}'", for amount remove the ", "("$1")"" part and add "|sort|uniq|wc -l".
Thanks ......
but I want to know these processes are running from where ??
What is the command and path ??
The "$2" that got printed is the PID, so you can use 'readlink' on the exe: "lsof -w -n|awk '/nohup.out/ {print $2}'|sort|uniq|xargs -iP readlink -f /proc/'P'/exe". The command used is in /proc/somepid/cmdline, which you can 'cat -v' by modifying the commandline given.
You can add some stuff to the end of unSpawn's command to call ps to get the command. Here I output a list of process ID and command. Just omit the "pid," from the -o option argument to print only the command:
It's all on one line here for easy command-line copy-pasting. If you want this in a script, it would be better to format it like this (which also makes it easier to read):
*edit*Unspawn's response beat me. Going to /proc is more efficient, and should work on pretty much any modern Linux. For compatibility with older Linuxes which don't support /proc, you can use the ps method I suggested above.*/edit*
Last edited by matthewg42; 04-18-2008 at 08:02 AM.
If you give lsof a file as argument it narrows the scope if you don't know which user nohups stuff (asserting you'll run this kind of stuff as root account user). And if you do know it, then 'fuser' is nearly twice as fast. Of course there's multiple solutions, so it's not to criticise yours.
Quote:
Originally Posted by matthewg42
For compatibility with older Linuxes which don't support /proc, you can use the ps method I suggested above.
I'm pretty sure I had /proc in kernel 2.0 but it does make me wonder, if not from /proc, where would 'ps' get its info from then?
If you give lsof a file as argument it narrows the scope if you don't know which user nohups stuff (asserting you'll run this kind of stuff as root account user). And if you do know it, then 'fuser' is nearly twice as fast. Of course there's multiple solutions, so it's not to criticise yours.
fuser - I always forget about this command. Somehow it seems to unlink it self from my memory. :-) The $HOME/nohup.out was my terminal test creeping into the post. Oops.
Quote:
I'm pretty sure I had /proc in kernel 2.0 but it does make me wonder, if not from /proc, where would 'ps' get its info from then?
I think ps has two modes - using /proc and traversing the kernel data structures directly. IIRC, it's a build time option. I believe the non-proc version needs to be set SUID root.
I don't remember when /proc started being used as standard on most distros. I remember it being something which it wasn't prudent to rely on at some point, but thinking about it that was quite a while ago now. I don't think I've installed a distro in the last five years which doesn't have /proc. Still, it's good to know an alternative, for example, when taking commands from a modern Linux to a different unix-like OS.
Actually, I'd love to know if anyone out there is using a Linux which doesn't have /proc. Perhaps one of the micro-distros?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.