* kill and pid files
@ 1997-06-18 7:25 Robert Stone
1997-06-18 20:16 ` Timothy J Luoma
0 siblings, 1 reply; 7+ messages in thread
From: Robert Stone @ 1997-06-18 7:25 UTC (permalink / raw)
To: zsh-users
I find myself using "kill -HUP $(cat /var/run/<program>.pid)"
constantly... in fact, as root I use that line much more often than using
a literal pid.
Is there any reason kill should not take a filename as an
argument? i.e. if the job specification is not a legal job name, or a
legal pid, why not try to open a file with that name and see if it's
first line is a valid pid?
Here's the idea, but this thing is horribly slow at times.
function mykill {
args=()
if ! kill "$argv[@]" 2> /dev/null
then while [ "$argv" ]
do case "$argv[1]"
in
-s)
args=("$args[@]" "$argv[1]" "$argv[2]")
shift 2
;;
-l)
args=("$args[@]" "$@")
shift "$#"
;;
-*)
args=("$args[@]" "$argv[1]")
shift
;;
*)
if echo "$argv[1]" | egrep -q '^%[0-9]+$'
then args=("$args[@]" "$argv[1]")
shift
elif echo "$argv[1]" | egrep -q '^[0-9]+$'
then args=("$args[@]" "$argv[1]")
shift
elif [ -f "$argv[1]" ] &&
head -1 "$argv[1]" | egrep -q '^[0-9]+$'
then args=("$args[@]" "$(head -1 "$argv[1]")")
shift
else args=("$args[@]" "$argv[1]")
shift
fi
;;
esac
done
kill "$args[@]"
fi
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kill and pid files
1997-06-18 7:25 kill and pid files Robert Stone
@ 1997-06-18 20:16 ` Timothy J Luoma
1997-06-19 6:42 ` Zoltan Hidvegi
1997-06-19 10:53 ` Vardhan Varma
0 siblings, 2 replies; 7+ messages in thread
From: Timothy J Luoma @ 1997-06-18 20:16 UTC (permalink / raw)
To: Robert Stone; +Cc: zsh-users
On Wed, 18 Jun 1997, Robert Stone wrote:
> Is there any reason kill should not take a filename as an
> argument? i.e. if the job specification is not a legal job name, or a
> legal pid, why not try to open a file with that name and see if it's
> first line is a valid pid?
well, I don't have the file part, but I use this
pid () {
for i in $*
do
echo `/bin/ps -auxwww | grep -v grep |
grep -w $i | awk '{print $2}' | tr -s '\012' ' '`
done
}
and then use it for something like
kill -HUP `pid sendmail`
but it doesn't have the nice expansion/matching stuff... more often than
not I know exactly what I want to kill. Note my version is only going to
match exactly (grep -w) and is case sensitive.
I don't know if this is anything like you wanted, I'm just trying to
contribute rather than just always asking ....
TjL
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kill and pid files
1997-06-18 20:16 ` Timothy J Luoma
@ 1997-06-19 6:42 ` Zoltan Hidvegi
1997-06-19 12:19 ` Matt Welland
1997-06-21 15:07 ` Timothy J. Luoma
1997-06-19 10:53 ` Vardhan Varma
1 sibling, 2 replies; 7+ messages in thread
From: Zoltan Hidvegi @ 1997-06-19 6:42 UTC (permalink / raw)
To: luomat; +Cc: rstone, zsh-users
> well, I don't have the file part, but I use this
>
> pid () {
>
> for i in $*
> do
> echo `/bin/ps -auxwww | grep -v grep |
> grep -w $i | awk '{print $2}' | tr -s '\012' ' '`
>
> done
>
> }
Oh, this is a really overcomplicated solution for a simple problem. How
about this:
pid () {
local i
for i
do
ps acx | sed -n "s/ *\([0-9]*\) .* $i *\$/\1/p"
done
}
Under Linux, you can even do that without ps or sed:
pid2 () {
local i
for i in /proc/<->/stat
do
[[ "$(< $i)" = *\((${(j:|:)~@})\)* ]] && echo $i:h:t
done
}
Zoltan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kill and pid files
1997-06-18 20:16 ` Timothy J Luoma
1997-06-19 6:42 ` Zoltan Hidvegi
@ 1997-06-19 10:53 ` Vardhan Varma
1 sibling, 0 replies; 7+ messages in thread
From: Vardhan Varma @ 1997-06-19 10:53 UTC (permalink / raw)
To: Timothy J Luoma; +Cc: Robert Stone, zsh-users
On Wed, 18 Jun 1997, Timothy J Luoma wrote:
> On Wed, 18 Jun 1997, Robert Stone wrote:
>
> > Is there any reason kill should not take a filename as an
> > argument? i.e. if the job specification is not a legal job name, or a
> > legal pid, why not try to open a file with that name and see if it's
> > first line is a valid pid?
>
> well, I don't have the file part, but I use this
>
> pid () {
>
> for i in $*
> do
> echo `/bin/ps -auxwww | grep -v grep |
> grep -w $i | awk '{print $2}' | tr -s '\012' ' '`
>
> done
>
> }
>
> and then use it for something like
>
> kill -HUP `pid sendmail`
>
thankfully i've a pidof on my linux box, so i can just say
kill -9 `pidof doit`
try it on you box who knows.....
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kill and pid files
1997-06-19 6:42 ` Zoltan Hidvegi
@ 1997-06-19 12:19 ` Matt Welland
1997-06-21 15:07 ` Timothy J. Luoma
1 sibling, 0 replies; 7+ messages in thread
From: Matt Welland @ 1997-06-19 12:19 UTC (permalink / raw)
To: Users Zsh
On Linux the killall command does what I need (I am forever doing "killall
diald" - but thats another story - *sigh*). However the little snippet
below just went into my .zshrc - AIX killall doesn't take process names as
parameters.
See - if you watch this list long enough at least 80% of those little
"argh - I must get around to writing that" bits of code will get written
for you!
--Matt
On Thu, 19 Jun 1997, Zoltan Hidvegi wrote:
> > well, I don't have the file part, but I use this
> >
> > pid () {
> >
> > for i in $*
> > do
> > echo `/bin/ps -auxwww | grep -v grep |
> > grep -w $i | awk '{print $2}' | tr -s '\012' ' '`
> >
> > done
> >
> > }
>
> Oh, this is a really overcomplicated solution for a simple problem. How
> about this:
>
> pid () {
> local i
> for i
> do
> ps acx | sed -n "s/ *\([0-9]*\) .* $i *\$/\1/p"
> done
> }
>
> Under Linux, you can even do that without ps or sed:
>
> pid2 () {
> local i
> for i in /proc/<->/stat
> do
> [[ "$(< $i)" = *\((${(j:|:)~@})\)* ]] && echo $i:h:t
> done
> }
>
> Zoltan
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kill and pid files
1997-06-19 6:42 ` Zoltan Hidvegi
1997-06-19 12:19 ` Matt Welland
@ 1997-06-21 15:07 ` Timothy J. Luoma
1 sibling, 0 replies; 7+ messages in thread
From: Timothy J. Luoma @ 1997-06-21 15:07 UTC (permalink / raw)
To: Zoltan Hidvegi; +Cc: rstone, zsh-users
-----BEGIN PGP SIGNED MESSAGE-----
Zoltan Hidvegi <hzoli@ny.frontiercomm.net> wrote in
Message-ID: <199706190642.CAA05741@hzoli.home>
Date: Thu, 19 Jun 1997
> Oh, this is a really overcomplicated solution for a simple problem. How
> about this:
>
> pid () {
> local i
> for i
> do
> ps acx | sed -n "s/ *\([0-9]*\) .* $i *\$/\1/p"
> done
> }
Yes but what if there is more than one process by that name?
I usually want to kill them all. This just kills one of them, whereas my
solution kills them all (that's what the 'tr' part is for).... however, it
may be "improvable":
Here's my function again
pid () {
for i in $*
do
echo `/bin/ps -auxwww | grep -v grep |
grep -w $i | awk '{print $2}' | tr -s '\012' ' '`
done
}
it also takes multiple arguments, in case you need to kill several things at once
TjL
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBM6vuTXTLzwEnIUsVAQH7GQP/RJCSAHfSE4kvkbd39ik9wlhnqEgw6vW6
eW9yrJesVN63mucnD8zjUqNu4KKmsA1AsN0o8s14zyn5f32iaH3bVUNRPI37DVlI
2x/mGqi7Rc4rrtNAKH2tu8wnmlsetq8nlJV828WQI+iJkE/vH4Bzidz8BkajMTAN
L0FiUOIglss=
=d8aX
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kill and pid files
@ 1997-06-18 13:05 Wez Furlong
0 siblings, 0 replies; 7+ messages in thread
From: Wez Furlong @ 1997-06-18 13:05 UTC (permalink / raw)
To: Robert Stone, zsh-users
On Jun 18, 12:25am, Robert Stone wrote:
: I find myself using "kill -HUP $(cat /var/run/<program>.pid)"
Isn't it more preferable to use $(< /var/run/<program>.pid) ?
This would bypass running cat, and certainly speed up your function by
using zsh's internal file reading.
Feel free to correct me if I'm wrong :)
--
Wez - Electronics Undergraduate at the University of York
URL : http://www.twinklestar.demon.co.uk/
Insult Of The Day: Thou dissembling fool-born miscreant!
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1997-06-21 15:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-06-18 7:25 kill and pid files Robert Stone
1997-06-18 20:16 ` Timothy J Luoma
1997-06-19 6:42 ` Zoltan Hidvegi
1997-06-19 12:19 ` Matt Welland
1997-06-21 15:07 ` Timothy J. Luoma
1997-06-19 10:53 ` Vardhan Varma
1997-06-18 13:05 Wez Furlong
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).