Can't grep name of process

Hi

I am trying to grep the name of the user running a specific process on one of my systems.

[apm@ccbapprts1 enterprisemanager]$ ps -efl | grep 'Introscope_WebView.lax' | grep -v grep| awk '{print $3}'
[apm@ccbapprts1 enterprisemanager]$ ps -efl | grep 'Introscope_WebView.lax'

0 S apm      14572 17108  0  80   0 - 28164 pipe_w 10:31 pts/4    00:00:00 grep --color=auto Introscope_WebView.lax

I would presume that would return "apm" but nothing appears

When I do the same code on a different unix server it works as expected:

[casupport@wycvlapph048 ~]$ ps -efl | grep 'Introscope_WebView.lax' | grep -v grep| awk '{print $3}'
50011
[casupport@wycvlapph048 ~]$ ps -efl | grep 'Introscope_WebView.lax'
0 S 50011      635 32387  0  80   0 - 25830 pipe_w 10:25 pts/0    00:00:00 grep Introscope_WebView.lax

Why is this?

Cheers
Alex

Hello Alex,

Do you have pgrep available? That might save some messing about. You could use pgrep to drive a ps command to get the information you need.

This might get you started:-

for pid in $(pgrep Introscope_WebView.lax)
do
   ps -o pid= -o user= -p $pid
done

Does that help?

Kind regards,
Robin

Mabe the process name is too long for pgrep then use pgrep -f (run on the full args).

---------- Post updated at 14:41 ---------- Previous update was at 13:52 ----------

In your post both the second grep(-only) does list the grep process and nothing else!?
--
The following uses the [ ] trick to not find itself (its own arguments) in the ps list.

ps -efl | awk '/Introscope_WebView[.]lax/ {print $3}'

While [ ] can contain any of the characters, a literal dot is preferred because it also changes the wildcard dot (regular expression!) into a literal dot.

2 Likes