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: How do I rid myself of the ' in this variable substitution? - comp ...It > should look like > > -A -s "C:\seamlessrdp\seamlessrdpshell.exe Notepad.exe" > > How do I get rid of those four extra stinking single quotes? comp.unix.shellsed -f 21 178 (3/26/2010 4:43:58 PM) Hi, This works great in vim, :v,^New,d to delete all lines that do not begin with "New" Please tell me the sed equiv so I can put ... Newbie question: How do I remove double spaces from a field ...iTunes newbie question: How do I remove duplicate tracks? - Ars ... iTunes newbie question: How do I remove duplicate ... iTunes Music) and do a search for " 1.mp3" (note ... How to DELETE the root password? - comp.databases.mysqlHow do I delete the root password from MySQL? I dont want to change it, because I know what the password is. I want it delete it so I can run mysql -... How to delete a printer using lpadmin? - comp.unix.solaris ...how do i delete a printer that I added with lpadmin? Thanks in advance, Gary. ... How to safely remove an external SCSI device? - comp.sys.sun.admin ...Hi, How do I safely remove an external SCSI device from a Sun box running Solaris 10 without powering the machine off? I had attached an external DV... Best way to delete old files? find & exec VS find & xargs - comp ..."Wim Cossement" <wcosseme@nospam.bcol.be> wrote: > Maybe running -exec rmdir \{\} \; to get rid of the dirs, > but how do I take care of the other problem? How the hell do I delete files on ZFS when file system is full ...I've got a problem on a Sun Blade 2000 running Solaris 10 update 7 with ZFS file systems. One of the file systems is full, but when I try to remove a ... Cropping a Picture into a Circle - comp.graphics.apps.paint-shop ...Hi all Can anyone tell me how to do this please? I have no problem with cropping a picture to get rid of unwanted bits round the edge but am now want... How to install Sun Solaris 10 inside VMware Workstation 5.5 - comp ...P.K.Stanton@gmail.com wrote: > Thank you for that... very helpful.... but a few questions.... > > 1) Do I remove the DVD when it first restarts and when do I put it back ... Deleting the first n characters of a field - comp.lang.awk ...I have some data in the following format: (Script(ID-VG)) I want to be able to remove the "(Script" part at the start of the field. Does anyone know... how to remove a stale mount point - comp.unix.solarisMy question is, how to do I remove this stale mount point w/o rebooting the server? I have restarted all the rpc services but that didn't help. Hp50g how do I erase individual plot functions - comp.sys.hp48 ...display video in a GUI - comp.soft-sys.matlab promptMessage = sprintf('Do you want to save the individual frames out ... end % Get rid of old image and plot. delete ... Delete line above and below the line which matches a pattern ...Hi, I want to search for a specific pattern in a file and delete one line above and one line below the line which matches the pattern. I'm trying to ... remove stack configuration of Catalyst 3750? - comp.dcom.sys.cisco ...Please help me to remove stack configuration of catalyst 3750! My tw Catalyst 3750 stack each other, and now I want to use each wit default configura... How do I remove the inverted P symbol that appears in my Word ...Best Answer: You need to go to the MENU item FORMAT once there you need to select PARAGRAPH Inside that pop-up screen menu there is an option to display ... how do i remove trojan:win32/sirefef.p each time i remove and ...How do i remove trojan:win32sirefef.p virus each time i remove and clean computer it reappears again even after turning off computer on instructions by clean up 7/24/2012 4:49:16 PM
|