LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   strange pgrep issue (https://www.linuxquestions.org/questions/linux-newbie-8/strange-pgrep-issue-638303/)

macushk 04-27-2008 10:07 PM

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

anomie 04-28-2008 03:13 PM

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'.

unSpawn 04-28-2008 03:48 PM

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?

macushk 04-28-2008 10:43 PM

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 !

Tinkster 04-29-2008 04:25 AM

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



Cheers,
Tink

unSpawn 04-29-2008 07:59 AM

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


All times are GMT -5. The time now is 12:47 AM.