LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
Search this Thread
Old 04-16-2008, 09:45 AM   #1
send2rawat
LQ Newbie
 
Registered: Jan 2007
Posts: 16

Rep: Reputation: 0
nohup check


HI,

Can anyone pls tell me how to check
1) How many nohup commands are running on the system.
2) what nohup commands are running on the system
 
Old 04-16-2008, 09:58 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,462
Blog Entries: 54

Rep: Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899
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".
 
Old 04-18-2008, 07:16 AM   #3
send2rawat
LQ Newbie
 
Registered: Jan 2007
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
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 ??
 
Old 04-18-2008, 07:56 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,462
Blog Entries: 54

Rep: Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899
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.
 
Old 04-18-2008, 08:01 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
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:
Code:
lsof $HOME/nohup.out |awk '!/^COMMAND/ { print $2 }' |sort -u |while read pid; do ps h -p $pid -o pid,command; done
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):
Code:
lsof $HOME/nohup.out \
  |awk '!/^COMMAND/ { print $2 }' \
  |sort -u \
  |while read pid; do 
      ps h -p $pid -o pid,command
   done
*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.
 
Old 04-18-2008, 08:57 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,462
Blog Entries: 54

Rep: Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899
Quote:
Originally Posted by matthewg42 View Post
lsof $HOME/nohup.out
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 View Post
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?
 
Old 04-18-2008, 09:29 AM   #7
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Quote:
Originally Posted by unSpawn View Post
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?
 
  


Reply

Tags
check, nohup


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
nohup sycamorex Linux - General 4 01-08-2008 05:49 PM
To use or not to use nohup entz Linux - Server 9 04-07-2007 04:52 PM
problem with nohup command and nohup file size vbseeker Linux - General 1 09-17-2006 11:36 AM
help on nohup vinayuh Linux - General 3 07-22-2005 12:24 PM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 AM


All times are GMT -5. The time now is 11:21 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration