How do I remove this "p"?

  • Follow


Hi,

I'm using Mac 10.6.3 with bash shell.  I want to identify the process
using a particular port for the purposes of passing that process ID to
kill -9.  So I have

lsof -w -n -i tcp:8080 -F ''

However this prints out the process ID with a "p" in front of it.  How
do I remove that "p" so that I can then pass the result to "kill
-9"?

Thanks, - Dave
0
Reply laredotornado (853) 3/25/2011 4:42:19 PM

>>>>> "Dave" == Dave  <laredotornado@zipmail.com> writes:

Dave> However this prints out the process ID with a "p" in front of it.  How
Dave> do I remove that "p" so that I can then pass the result to "kill
Dave> -9"?

No no no.  Don't use kill -9.

It doesn't give the process a chance to cleanly:

1) release IPC resources (shared memory, semaphores, message queues)

2) clean up temp files

3) inform its children that it is going away

4) reset its terminal characteristics

and so on and so on and so on.

Generally, send 15 (SIGTERM), and wait a second or two, and if that
doesn't work, send 2 (SIGINT), and if that doesn't work, send 1
(SIGHUP).  If that doesn't, REMOVE THE BINARY because the program is
badly behaved!

Don't use kill -9.  Don't bring out the combine harvester just to tidy
up the flower pot.

Just another Useless Use of Usenet,

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
0
Reply merlyn 3/25/2011 5:27:58 PM


On Mar 25, 12:27=A0pm, mer...@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "Dave" =3D=3D Dave =A0<laredotorn...@zipmail.com> writes:
>
> Dave> However this prints out the process ID with a "p" in front of it. =
=A0How
> Dave> do I remove that "p" so that I can then pass the result to "kill
> Dave> -9"?
>
> No no no. =A0Don't use kill -9.
>
> It doesn't give the process a chance to cleanly:
>
> 1) release IPC resources (shared memory, semaphores, message queues)
>
> 2) clean up temp files
>
> 3) inform its children that it is going away
>
> 4) reset its terminal characteristics
>
> and so on and so on and so on.
>
> Generally, send 15 (SIGTERM), and wait a second or two, and if that
> doesn't work, send 2 (SIGINT), and if that doesn't work, send 1
> (SIGHUP). =A0If that doesn't, REMOVE THE BINARY because the program is
> badly behaved!
>
> Don't use kill -9. =A0Don't bring out the combine harvester just to tidy
> up the flower pot.
>
> Just another Useless Use of Usenet,
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 00=
95
> <mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> Seehttp://methodsandmessages.posterous.com/for Smalltalk discussion

Ok, your passion alone convinces me to try your path.  But my
questions remains -- how do I get the process ID from the output
returned and then how do I send a SIGTERM to it? - Dave
0
Reply laredotornado 3/25/2011 6:32:17 PM

On March 25, 2011 12:42, in comp.unix.shell, laredotornado@zipmail.com
wrote:

> Hi,
> 
> I'm using Mac 10.6.3 with bash shell.  I want to identify the process
> using a particular port for the purposes of passing that process ID to
> kill -9.  So I have
> 
> lsof -w -n -i tcp:8080 -F ''
> 
> However this prints out the process ID with a "p" in front of it.  How
> do I remove that "p" so that I can then pass the result to "kill
> -9"?

lsof -w -n -i tcp:8080 -F '' | sed 's/p//'


-- 
Lew Pitcher
Master Codewright & JOAT-in-training   | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
----------      Slackware - Because I know what I'm doing.         ------


0
Reply Lew 3/25/2011 6:52:48 PM

On 2011-03-25, Dave <laredotornado@zipmail.com> wrote:
> Hi,
>
> I'm using Mac 10.6.3 with bash shell.  I want to identify the process
> using a particular port for the purposes of passing that process ID to
> kill -9.  So I have
>
> lsof -w -n -i tcp:8080 -F ''
>
> However this prints out the process ID with a "p" in front of it.  How
> do I remove that "p" so that I can then pass the result to "kill
> -9"?
>
> Thanks, - Dave

 lsof -w -n -i tcp:8080 -F '' | sed 's/p//'


-- 
A wise man cannot be insulted. If the insult has no meaning, he ignores
it. If the insult does have meaning, he deserves it.
0
Reply Bill 3/25/2011 7:21:09 PM

On Fri, 25 Mar 2011 11:32:17 -0700, laredotornado@zipmail.com wrote:

> On Mar 25, 12:27 pm, mer...@stonehenge.com (Randal L. Schwartz) wrote:
>> >>>>> "Dave" == Dave  <laredotorn...@zipmail.com> writes:
>>
>> Dave> However this prints out the process ID with a "p" in front of it.
>>  How Dave> do I remove that "p" so that I can then pass the result to
>> "kill Dave> -9"?
>>
>> No no no.  Don't use kill -9.
>>
>> It doesn't give the process a chance to cleanly:
>>
>> 1) release IPC resources (shared memory, semaphores, message queues)
>>
>> 2) clean up temp files
>>
>> 3) inform its children that it is going away
>>
>> 4) reset its terminal characteristics
>>
>> and so on and so on and so on.
>>
>> Generally, send 15 (SIGTERM), and wait a second or two, and if that
>> doesn't work, send 2 (SIGINT), and if that doesn't work, send 1
>> (SIGHUP).  If that doesn't, REMOVE THE BINARY because the program is
>> badly behaved!
>>
>> Don't use kill -9.  Don't bring out the combine harvester just to tidy
>> up the flower pot.
>>
>> Just another Useless Use of Usenet,
>>
>> --
>> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
>> 0095 <mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
>> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
>> Seehttp://methodsandmessages.posterous.com/for Smalltalk discussion
> 
> Ok, your passion alone convinces me to try your path.  But my questions
> remains -- how do I get the process ID from the output returned and then
> how do I send a SIGTERM to it? - Dave

| sed -e 's/^p//g' 
0
Reply goarilla 3/25/2011 7:35:25 PM

On Fri, 25 Mar 2011 12:42:19 -0400, Dave <laredotornado@zipmail.com> wrote:


> lsof -w -n -i tcp:8080 -F ''
> However this prints out the process ID with a "p" in front of it.  How
> do I remove that "p" so that I can then pass the result to "kill

pidwithp="$(lsof -w -n -i tcp:59385 -F '')"
pidwithoutp="${pidwithp:1}"

Regards, Dave Hodgins

-- 
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)
0
Reply David 3/25/2011 8:31:16 PM

Dave <laredotornado@zipmail.com> writes:

> I'm using Mac 10.6.3 with bash shell. I want to identify the process
> using a particular port for the purposes of passing that process ID to
> kill -9. So I have
>
> lsof -w -n -i tcp:8080 -F ''
>
> However this prints out the process ID with a "p" in front of it.  How
> do I remove that "p"

Annoyingly, the ‘lsof’ program apparently can't be told not to put in
there in the first place (which would be the best solution).

You could use ‘sed(1)’ to strip off the leading ‘p’. Here's an example
using a conservative regex (it could be simplified if you don't care
about false positives):

    $ printf "%s\n" p1076
    p1076
    $ printf "%s\n" p1076 | sed -e 's/p\([[:digit:]]\+\)/\1/'
    1076

Alternatively, you can capture the output to a variable, and then use
Bash's flexible expansion rules to do the job:

    $ result=$( printf "%s\n" p1076 ) ; printf "%s\n" $result
    p1076
    $ result=$( printf "%s\n" p1076 ) ; printf "%s\n" ${result#p}
    1076

> so that I can then pass the result to "kill -9"?

First, use the signal names instead of needing to remember (and
sometimes mistaking) the signal numbers. The signal you're talking about
is named “KILL”, so ‘kill -KILL 1076’.

Second, don't use the “KILL” signal except as a last resort; it ensures
the program will die in the worst possible way, doing no clean up at
all.

Instead, use the more polite signals first: try “TERM”, which will work
for most processes that aren't confused. ‘kill -TERM 1076’. This is the
default signal sent by the (now somewhat mis-named) ‘kill(1)’ program.

See the ‘signal(7)’ manual page for more about the signals that can be
used.

-- 
 \           “People are very open-minded about new things, as long as |
  `\         they're exactly like the old ones.” —Charles F. Kettering |
_o__)                                                                  |
Ben Finney
0
Reply Ben 3/25/2011 8:34:00 PM

On Fri, 25 Mar 2011 16:31:16 -0400, David W. Hodgins <dwhodgins@nomail.afraid.org> wrote:

> On Fri, 25 Mar 2011 12:42:19 -0400, Dave <laredotornado@zipmail.com> wrote:
>> lsof -w -n -i tcp:8080 -F ''
>> However this prints out the process ID with a "p" in front of it.  How
>> do I remove that "p" so that I can then pass the result to "kill

> pidwithp="$(lsof -w -n -i tcp:59385 -F '')"
> pidwithoutp="${pidwithp:1}"

Opps.  That should have been 8080 instead the the 59385.  I don't
have anything using 8080, but do have something on 59395.

Regards, Dave Hodgins

-- 
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)
0
Reply David 3/25/2011 8:48:57 PM

On 2011-03-25, David W. Hodgins wrote:
> On Fri, 25 Mar 2011 12:42:19 -0400, Dave <laredotornado@zipmail.com> wrote:
>
>
>> lsof -w -n -i tcp:8080 -F ''
>> However this prints out the process ID with a "p" in front of it.  How
>> do I remove that "p" so that I can then pass the result to "kill
>
> pidwithp="$(lsof -w -n -i tcp:59385 -F '')"
> pidwithoutp="${pidwithp:1}"

  Or, portably:

pidwithoutp=${pidwithp#?}

-- 
   Chris F.A. Johnson, author           <http://shell.cfajohnson.com/>
   ===================================================================
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)

0
Reply Chris 3/26/2011 2:37:54 PM

In article <232bef95-1aa9-43c9-a738-25c3d9f6d887@i39g2000prd.googlegroups.com>,
Dave  <laredotornado@zipmail.com> wrote:
>Hi,
>
>I'm using Mac 10.6.3 with bash shell.  I want to identify the process
>using a particular port for the purposes of passing that process ID to
>kill -9.  So I have
>
>lsof -w -n -i tcp:8080 -F ''
>
>However this prints out the process ID with a "p" in front of it.  How
>do I remove that "p" so that I can then pass the result to "kill
>-9"?

Use "lsof -t", which is intended for exactly that purpose.

	John
-- 
John DuBois  spcecdt@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/
0
Reply spcecdt 3/26/2011 4:06:30 PM

goarilla <goarilla@invalid.invalid> writes:
> On Fri, 25 Mar 2011 11:32:17 -0700, laredotornado@zipmail.com wrote:
[...]
>> Ok, your passion alone convinces me to try your path.  But my questions
>> remains -- how do I get the process ID from the output returned and then
>> how do I send a SIGTERM to it? - Dave
>
> | sed -e 's/^p//g' 

What's the trailing 'g' for?  (I know what it means; it just isn't
necessary here.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
0
Reply Keith 3/26/2011 9:31:58 PM

In article <lny6417elt.fsf@nuthaus.mib.org>,
 Keith Thompson <kst-u@mib.org> wrote:

> goarilla <goarilla@invalid.invalid> writes:
> > On Fri, 25 Mar 2011 11:32:17 -0700, laredotornado@zipmail.com wrote:
> [...]
> >> Ok, your passion alone convinces me to try your path.  But my questions
> >> remains -- how do I get the process ID from the output returned and then
> >> how do I send a SIGTERM to it? - Dave
> >
> > | sed -e 's/^p//g' 
> 
> What's the trailing 'g' for?  (I know what it means; it just isn't
> necessary here.)

I'll bet he's just in the habit of always using it, since most of the 
time it's what you want.  In this case it's superfluous, but doesn't 
hurt.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
0
Reply Barry 3/27/2011 6:49:55 AM

On Sun, 27 Mar 2011 03:49:55 -0400, Barry Margolin wrote:

> In article <lny6417elt.fsf@nuthaus.mib.org>,
>  Keith Thompson <kst-u@mib.org> wrote:
> 
>> goarilla <goarilla@invalid.invalid> writes:
>> > On Fri, 25 Mar 2011 11:32:17 -0700, laredotornado@zipmail.com wrote:
>> [...]
>> >> Ok, your passion alone convinces me to try your path.  But my
>> >> questions remains -- how do I get the process ID from the output
>> >> returned and then how do I send a SIGTERM to it? - Dave
>> >
>> > | sed -e 's/^p//g'
>> 
>> What's the trailing 'g' for?  (I know what it means; it just isn't
>> necessary here.)
> 
> I'll bet he's just in the habit of always using it, since most of the
> time it's what you want.  In this case it's superfluous, but doesn't
> hurt.

I thought the same thing right after i posted it, i guess
it's rote memorisation having a swing at me.
0
Reply kevin.paulus1650 (29) 4/1/2011 12:06:50 PM

13 Replies
221 Views

(page loaded in 0.521 seconds)

Similiar Articles:


















7/24/2012 4:49:16 PM


Reply: