Re: How do I remove this "p"?
- From: Ben Finney <ben+unix@xxxxxxxxxxxxxxx>
- Date: Sat, 26 Mar 2011 07:34:00 +1100
Dave <laredotornado@xxxxxxxxxxx> 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
.
- References:
- How do I remove this "p"?
- From: Dave
- How do I remove this "p"?
- Prev by Date: Re: How do I remove this "p"?
- Next by Date: Re: How do I remove this "p"?
- Previous by thread: Re: How do I remove this "p"?
- Next by thread: Re: How do I remove this "p"?
- Index(es):
Relevant Pages
|