LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-27-2008, 11:07 PM   #1
macushk
LQ Newbie
 
Registered: Oct 2006
Posts: 7

Rep: Reputation: 0
strange pgrep issue


I use the "pgrep -f tomcat" to find the process id of the running tomcat. But it return a long list of PIDs which most of them are not the pid of anything running process. What's the problem?
eg.
pgrep -f tomcat
...

16395
16402
16403
16404
16405
16406
16407
16408
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16464
...

If I use "ps" to find the pid, the 16395 and 16464 are the pid of the tomcat process.

Please help
 
Old 04-28-2008, 04:13 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Keep in mind that the -f option to pgrep matches the full command line. If you happen to be running other commands that contain 'tomcat' (e.g. in their directory name) in them, they'll match.

Quick way to figure this out:
$ ps -ef | less

Then use less's search facility to find all the occurrences of the word 'tomcat'.
 
Old 04-28-2008, 04:48 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Pgrep can use simple globbing n such, so 'pgrep -f '/sb*/tomcat '' shouldn't match /usr/bin/tomcat.sh. Also you want to use "-l" during testing stage since it'll show what commandline if pgrepped. Then maybe something Java-based like 'jps' could work "better" for Java-based apps?
 
Old 04-28-2008, 11:43 PM   #4
macushk
LQ Newbie
 
Registered: Oct 2006
Posts: 7

Original Poster
Rep: Reputation: 0
The most strange problem is that I can sure there is only 2 running process which contain "tomcat" in the command line.
If I use "pgrep -fl tomcat", I will show the full command, but most of the are invlide PID and command.

eg.
"pgrep -fl tomcat"
...
24359 /opt/com/j2sdk1.4.2_05/bin/java -Xms512m -Xmx51 .... tomcat
24443 /opt/com/j2sdk1.4.2_05/bin/java -Xms384m -Xmx384m -Dj ..... tomcat
24446 /opt/com/j2sdk1.4.2_05/bin/java -Xms384m -Xmx384m ..... tomcat
....
....

But, only the pid 24359 is the real PID, other are invalid pid. ( no this running process by "px pid" )

Please help !
 
Old 04-29-2008, 05:25 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Well ... why don't you compare the output of a
ps aux | grep -i tomcat
with what pgrep has to say?



Cheers,
Tink
 
Old 04-29-2008, 08:59 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
...or maybe something Java-based like 'jps' could work "better" for Java-based apps?
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pgrep on windows os melinda_sayang General 1 02-16-2007 02:02 PM
pkill and pgrep hang and cannot be killed Zoombie Linux - Software 0 01-08-2006 01:19 AM
strange c issue exvor Programming 8 01-29-2005 03:23 PM
help me on a strange issue. newpenguin Linux - General 11 10-06-2002 04:42 PM
pgrep/pkill d3funct Linux - General 0 09-18-2001 03:30 PM


All times are GMT -5. The time now is 09:12 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration