LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 07-26-2006, 04:20 AM   #1
closet geek
Member
 
Registered: Apr 2003
Location: England
Posts: 146

Rep: Reputation: 15
Strange lsof behaviour, possible bug?


Why is it when I run:

lsof -p `ps aux | grep crond | grep -v grep | awk '{print $2}'`

I get the output expected, but when I run:

lsof -p `ps aux | grep bash | grep -v grep | awk '{print $2}'`

I get an error. Even more confusing is when I run:

ps aux | grep bash | grep -v grep | awk '{print $2}'

on its own I get the pid as expected and when I manually paste that pid into lsof -p it runs as expected also?

Am I the only one?

cg
 
Old 07-26-2006, 07:34 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,450
Blog Entries: 54

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
Supplying multiple PID's. Lsof doesn't like that unless you use the correct syntax to string it together (-a).
Try "for pid in $(pgrep -f bash); do lsof -p $pid; done" or "pgrep -f bash|xargs -iP lsof -p 'P'" or lsof $(pgrep -f bash|awk '{print "-a -p " $1}')
 
Old 07-26-2006, 07:53 AM   #3
closet geek
Member
 
Registered: Apr 2003
Location: England
Posts: 146

Original Poster
Rep: Reputation: 15
Thanks for your workarounds, but I'm not so sure your reason for it not working is true, when I run:

ps aux | grep bash | grep -v grep | awk '{print $2}'

I get only one number?

cg
 
Old 07-26-2006, 08:27 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,450
Blog Entries: 54

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
Post the *exact* error you get? Appending "2>&1|tee /tmp/log" to your command should save all output to /tmp/log for perusal/posting.
 
Old 07-26-2006, 08:43 AM   #5
closet geek
Member
 
Registered: Apr 2003
Location: England
Posts: 146

Original Poster
Rep: Reputation: 15
Here it is:

lsof: status error on 1541: No such file or directory
lsof 4.72
latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
usage: [-?abhlnNoOPRstUvV] [+|-c c] [+|-d s] [+D D] [+|-f]
[-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]]
[-p s] [+|-r [t]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Use the ``-h'' option to get more help information.

It's worth noting that the number 1541 changes everytime I try to run the command and has no relation at all to the bash pid.

This happens on 5 different servers all running CentOS.

cg
 
Old 07-26-2006, 06:28 PM   #6
closet geek
Member
 
Registered: Apr 2003
Location: England
Posts: 146

Original Poster
Rep: Reputation: 15
Can anyone spot why this is?

cg
 
Old 07-26-2006, 06:30 PM   #7
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Yep, sure can. The backticks cause another instance of bash to be run, which means the command in the backticks returns two pids, causing the error.
 
Old 07-26-2006, 06:45 PM   #8
closet geek
Member
 
Registered: Apr 2003
Location: England
Posts: 146

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Matir
Yep, sure can. The backticks cause another instance of bash to be run, which means the command in the backticks returns two pids, causing the error.


I thought the backticks meant "execute this first" ?

cg
 
Old 07-26-2006, 06:57 PM   #9
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
The backticks mean "start a new sub-shell, run this, and replace this with the results of that". But yes, it does get run first... just by a child process of the parent bash.
 
Old 07-27-2006, 02:18 AM   #10
closet geek
Member
 
Registered: Apr 2003
Location: England
Posts: 146

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Matir
The backticks mean "start a new sub-shell, run this, and replace this with the results of that". But yes, it does get run first... just by a child process of the parent bash.
Ahh, I'm with you now - thanks for your help!

cg
 
  


Reply


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
strange behaviour marsques Slackware 11 02-15-2006 06:05 PM
Strange Behaviour! joshuarowley LQ Suggestions & Feedback 1 12-08-2005 03:36 PM
Strange behaviour Anmol Suse/Novell 2 10-27-2005 11:05 PM
Scribus: Text over two frames: Behaviour Bug or not? furryspider Linux - Software 2 09-04-2004 05:53 AM
Strange Behaviour mikeyt_3333 Linux - General 4 08-06-2001 03:07 PM


All times are GMT -5. The time now is 05:52 PM.

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