Re: How do I remove this "p"?



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
.



Relevant Pages

  • Re: [SLE] KILL in 9.3 not killing process
    ... work, opening a terminal and using kill (pid number) doesn't work, nor ... When a program receives a signal, the signal handler for that signal is ... For most signals that ...
    (SuSE)
  • Re: Periodic Fedora 9 system hangs with jumpy mouse
    ... kill -TERM ... just to make sure it wasn't sending signals. ... Other than the Xorg process, ... a running state consuming 100% cpu; ...
    (Fedora)
  • Re: mpd has hung
    ... Today mpd process hung and I cannot kill it with -9 signal, ... SIGKILL, you cannot kill it, and the signals are queued). ... If you are still seeing the hang and have DDB support in your kernel, ...
    (freebsd-net)
  • Re: mpd has hung
    ... Today mpd process hung and I cannot kill it with -9 signal, ... SIGKILL, you cannot kill it, and the signals are queued). ... If you are still seeing the hang and have DDB support in your kernel, ...
    (freebsd-net)
  • Re: signals generated ONLY by abort, kill, or raise
    ... > KNOW that the signal was generated by abort, kill, or raise? ... > It seems to me that there are only four portable signals that can ONLY be ...
    (comp.unix.programmer)