All of lore.kernel.org
 help / color / mirror / Atom feed
* Extraction of PID
@ 2003-07-26  6:58 Peter
  2003-07-26  8:11 ` John Kelly
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Peter @ 2003-07-26  6:58 UTC (permalink / raw)
  To: linux

Hi,

How do I isolate from a line like

1865 tty2 00:00:18 exmh

the first 4 numbers which is the PID. I get it with "ps -a --pid 1111 | grep 
exmh".

Thanks & regards
-- 
Peter

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Extraction of PID
  2003-07-26  6:58 Extraction of PID Peter
@ 2003-07-26  8:11 ` John Kelly
  2003-07-26  8:22 ` pa3gcu
  2003-07-26 10:57 ` chuck gelm
  2 siblings, 0 replies; 5+ messages in thread
From: John Kelly @ 2003-07-26  8:11 UTC (permalink / raw)
  To: linux

On Saturday 26 July 2003 7:58 am, Peter wrote:

>Hi,
>
>How do I isolate from a line like
>
>1865 tty2 00:00:18 exmh
>
>the first 4 numbers which is the PID. I get it with "ps -a --pid 1111 | grep 
>exmh".
Hi,
As usual in 'nix there are several different ways of doing this.
My first guess was:

ps -a -pid 1111 | grep exmh | awk '{print $1}'

Which works fine for me on my Redhat box.

Second guess was:

ps -a -pid 1111 | awk '/exmh/{print $1}' 

Which also worked fine.

Since not many people use awk, I though I would try a few examples with the 
cut command.

ps -a -pid 1111 | grep exmh | cut -d' ' -f1

This example works but I had to use the -d option to specify the delimiter.
If you were sure the pid was only going to be four characters long, you could 
use:

ps -a -pid 1111 | grep exmh | cut -c1-4

I have just spent the past ten minutes messing about using sed to do this too 
- but I don't think any sane person would used sed to do something like this. 
But for what it is worth, here is my sed example

ps -a -pid 1111 | sed -ne '/exmh/s/ tty.*$//'


Your best bet is probably to use the 
ps -a -pid 1111 | grep exmh | cut -d' ' -f1
example. But rememeber that there is hours to fun to be had messing about 
with obscure programs on nix systems. :-)

regards

John Kelly
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Extraction of PID
  2003-07-26  6:58 Extraction of PID Peter
  2003-07-26  8:11 ` John Kelly
@ 2003-07-26  8:22 ` pa3gcu
  2003-07-27  5:36   ` Peter
  2003-07-26 10:57 ` chuck gelm
  2 siblings, 1 reply; 5+ messages in thread
From: pa3gcu @ 2003-07-26  8:22 UTC (permalink / raw)
  To: Peter, linux

On Saturday 26 July 2003 08:58, Peter wrote:
> Hi,
>
> How do I isolate from a line like
>
> 1865 tty2 00:00:18 exmh
>
> the first 4 numbers which is the PID. I get it with "ps -a --pid 1111 |
> grep exmh".

If your system has "pidof" installed; then

'pidof exmh'

> Thanks & regards

-- 
If the Linux community is a bunch of theives because they
try to imitate windows programs, then the Windows community
is built on organized crime.

Regards Richard
pa3gcu@zeelandnet.nl
http://people.zeelandnet.nl/pa3gcu/



-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Extraction of PID
  2003-07-26  6:58 Extraction of PID Peter
  2003-07-26  8:11 ` John Kelly
  2003-07-26  8:22 ` pa3gcu
@ 2003-07-26 10:57 ` chuck gelm
  2 siblings, 0 replies; 5+ messages in thread
From: chuck gelm @ 2003-07-26 10:57 UTC (permalink / raw)
  To: Peter, linux-newbie

ps -a --pid 1111 | grep exmh | cut -b 2-5

HTH, Chuck

Peter wrote:
> 
> Hi,
> 
> How do I isolate from a line like
> 
> 1865 tty2 00:00:18 exmh
> 
> the first 4 numbers which is the PID. I get it with 
"ps -a --pid 1111 | grep > exmh".
                         ^
                         ?

> 
> Thanks & regards
> --
> Peter
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Extraction of PID
  2003-07-26  8:22 ` pa3gcu
@ 2003-07-27  5:36   ` Peter
  0 siblings, 0 replies; 5+ messages in thread
From: Peter @ 2003-07-27  5:36 UTC (permalink / raw)
  To: linux-newbie

Wonderful --who will ever fathom what hidden treasures there are in a Linux 
box.

I needed this PID of pppd for my little script which shows in a terminal From: 
and Subject: as mail is coming in; tail -f --pid PID file.

Thanks again


-- 
Peter

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-07-27  5:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-26  6:58 Extraction of PID Peter
2003-07-26  8:11 ` John Kelly
2003-07-26  8:22 ` pa3gcu
2003-07-27  5:36   ` Peter
2003-07-26 10:57 ` chuck gelm

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.