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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-26-2006, 04:20 AM
|
#1
|
|
Member
Registered: Apr 2003
Location: England
Posts: 146
Rep:
|
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
|
|
|
|
07-26-2006, 07:34 AM
|
#2
|
|
Moderator
Registered: May 2001
Posts: 24,805
|
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}')
|
|
|
|
07-26-2006, 07:53 AM
|
#3
|
|
Member
Registered: Apr 2003
Location: England
Posts: 146
Original Poster
Rep:
|
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
|
|
|
|
07-26-2006, 08:27 AM
|
#4
|
|
Moderator
Registered: May 2001
Posts: 24,805
|
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.
|
|
|
|
07-26-2006, 08:43 AM
|
#5
|
|
Member
Registered: Apr 2003
Location: England
Posts: 146
Original Poster
Rep:
|
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
|
|
|
|
07-26-2006, 06:28 PM
|
#6
|
|
Member
Registered: Apr 2003
Location: England
Posts: 146
Original Poster
Rep:
|
Can anyone spot why this is?
cg
|
|
|
|
07-26-2006, 06:30 PM
|
#7
|
|
Moderator
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,505
Rep: 
|
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.
|
|
|
|
07-26-2006, 06:45 PM
|
#8
|
|
Member
Registered: Apr 2003
Location: England
Posts: 146
Original Poster
Rep:
|
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
|
|
|
|
07-26-2006, 06:57 PM
|
#9
|
|
Moderator
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,505
Rep: 
|
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.
|
|
|
|
07-27-2006, 02:18 AM
|
#10
|
|
Member
Registered: Apr 2003
Location: England
Posts: 146
Original Poster
Rep:
|
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
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:26 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|