zsh-workers
 help / color / mirror / code / Atom feed
* Can Zsh do this for me?
@ 2003-09-02 12:08 DervishD
  2003-09-02 12:25 ` Oliver Kiddle
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: DervishD @ 2003-09-02 12:08 UTC (permalink / raw)
  To: Zsh

    Hi all :))

    I'm writing a command to kill a process by name, not by PID, just
like 'pidof' but without using 'pidof' ;))) It's pretty easy using
the ps command and a pipeline. Right know, it can be written like
this:

    ps xh | grep name | tr -s " " | cut -d " " -f 2

    Since it will be called by root to kill root processes, it will
do, and with my ps binary, the options are correct. But I don't want
to start four processes just to get the pid of one of them. I can use
my /proc filesystem, but I was wondering if Zsh has some facility to
get the process ID using the command name, or if I can write the
above pipeline in a shorter form using some Zsh capability.

    BTW, I want to write a 'ps' command on my own because I don't
like the procps one available for Linux, nor the others out there,
and I think that with the zsh/stat module I could do it in a shell
script :)))

    Well, thanks in advance :))

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Can Zsh do this for me?
  2003-09-02 12:08 Can Zsh do this for me? DervishD
@ 2003-09-02 12:25 ` Oliver Kiddle
  2003-09-02 19:21   ` DervishD
  2003-09-02 12:38 ` Alexey Tourbin
  2003-09-02 13:30 ` Jason Price
  2 siblings, 1 reply; 8+ messages in thread
From: Oliver Kiddle @ 2003-09-02 12:25 UTC (permalink / raw)
  To: DervishD; +Cc: Zsh

DervishD wrote:

>     I'm writing a command to kill a process by name, not by PID, just
> like 'pidof' but without using 'pidof' ;))) It's pretty easy using
> the ps command and a pipeline. Right know, it can be written like
> this:
> 
>     ps xh | grep name | tr -s " " | cut -d " " -f 2
> 

This doesn't seem to work for PIDs >= 10000 where there is no initial
space in the ps listing.

>     Since it will be called by root to kill root processes, it will
> do, and with my ps binary, the options are correct. But I don't want
> to start four processes just to get the pid of one of them. I can use
> my /proc filesystem, but I was wondering if Zsh has some facility to
> get the process ID using the command name, or if I can write the
> above pipeline in a shorter form using some Zsh capability.

You can write the command-line as:
    ${${${(M)${(f)"$(ps xh)"}:#*$name*}## #}%% *}

(M) and :# does the grep. ## # removes initial space and the %% * does
the job of cut.

Use $~name if you'd like to use patterns for name. And if you only want
one PID, use [1] on the end of it all.

>     BTW, I want to write a 'ps' command on my own because I don't
> like the procps one available for Linux, nor the others out there,
> and I think that with the zsh/stat module I could do it in a shell
> script :)))

I'm not quite sure how you'd do that using zsh/stat (using /proc?) but
good luck with it.

Oliver


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Can Zsh do this for me?
  2003-09-02 12:08 Can Zsh do this for me? DervishD
  2003-09-02 12:25 ` Oliver Kiddle
@ 2003-09-02 12:38 ` Alexey Tourbin
  2003-09-02 13:07   ` Peter Stephenson
  2003-09-02 19:22   ` DervishD
  2003-09-02 13:30 ` Jason Price
  2 siblings, 2 replies; 8+ messages in thread
From: Alexey Tourbin @ 2003-09-02 12:38 UTC (permalink / raw)
  To: Zsh

[-- Attachment #1: Type: text/plain, Size: 224 bytes --]

On Tue, Sep 02, 2003 at 02:08:46PM +0200, DervishD wrote:
>     I'm writing a command to kill a process by name, not by PID, just
> like 'pidof' but without using 'pidof' ;))) It's pretty easy using

Do you have killall(1)?

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Can Zsh do this for me?
  2003-09-02 12:38 ` Alexey Tourbin
@ 2003-09-02 13:07   ` Peter Stephenson
  2003-09-02 19:22   ` DervishD
  1 sibling, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2003-09-02 13:07 UTC (permalink / raw)
  To: Zsh

Alexey Tourbin wrote:
> 
> --jI8keyz6grp/JLjh
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> 
> On Tue, Sep 02, 2003 at 02:08:46PM +0200, DervishD wrote:
> >     I'm writing a command to kill a process by name, not by PID, just
> > like 'pidof' but without using 'pidof' ;))) It's pretty easy using
> 
> Do you have killall(1)?

Careful, since there are two versions of this --- Solaris has a
`killall' which does exactly that; it's used by shutdown.  The other
one, common on Linux, which takes a command name or similar and kills
only those, is more useful.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Can Zsh do this for me?
  2003-09-02 12:08 Can Zsh do this for me? DervishD
  2003-09-02 12:25 ` Oliver Kiddle
  2003-09-02 12:38 ` Alexey Tourbin
@ 2003-09-02 13:30 ` Jason Price
  2003-09-02 19:57   ` DervishD
  2 siblings, 1 reply; 8+ messages in thread
From: Jason Price @ 2003-09-02 13:30 UTC (permalink / raw)
  To: Zsh

>     BTW, I want to write a 'ps' command on my own because I don't
> like the procps one available for Linux, nor the others out there,
> and I think that with the zsh/stat module I could do it in a shell
> script :)))

Under solaris and debian linux, there's something called pkill(1) that will
take a name, and kill it.

BTW: if you're re-writing linux PS as a shell script to learn a lot of
linux and zsh internals, go right ahead.  If you're just annoyed by how it
works, take a long look through the man page.  It's amazingly powerful and
flexable.  It looks like you were using the BSD flavor of args.  If you
want SYSVish args, just use a hyphen.  I.E.: 'ps -ef'.  See the man page for
more details than you probably want.

ps.  The only thing that competes with ls for number of options.

Jason


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Can Zsh do this for me?
  2003-09-02 12:25 ` Oliver Kiddle
@ 2003-09-02 19:21   ` DervishD
  0 siblings, 0 replies; 8+ messages in thread
From: DervishD @ 2003-09-02 19:21 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh

    Hi Oliver :)

 * Oliver Kiddle <okiddle@yahoo.co.uk> dixit:
> > Right know, it can be written like this:
> >     ps xh | grep name | tr -s " " | cut -d " " -f 2
> This doesn't seem to work for PIDs >= 10000 where there is no initial
> space in the ps listing.

    Oh, yes, you're true, it was just a quick hack, not a good work ;))
The point was the four processes neeced for this, and your answer
below. Thanks a lot!!

> > get the process ID using the command name, or if I can write the
> > above pipeline in a shorter form using some Zsh capability.
> You can write the command-line as:
>     ${${${(M)${(f)"$(ps xh)"}:#*$name*}## #}%% *}
> (M) and :# does the grep. ## # removes initial space and the %% * does
> the job of cut.
> Use $~name if you'd like to use patterns for name. And if you only want
> one PID, use [1] on the end of it all.

    That's great! A very good example of what I was looking for: the
power of Zsh to do things faster ;)))) Right now I don't understand
the entire line (but I'm new to expansions...), but I will take a
look at the manual. Thanks a lot, truly :)

> >     BTW, I want to write a 'ps' command on my own because I don't
> > like the procps one available for Linux, nor the others out there,
> > and I think that with the zsh/stat module I could do it in a shell
> > script :)))
> I'm not quite sure how you'd do that using zsh/stat (using /proc?) but
> good luck with it.

    The point is to examine /proc. Some of the things can be done
using 'cat' and the like, but a couple of them must be done with the
stat syscall, and maybe zsh/mapfile to read the file contents in an
easy way. Really, Zsh is just incredible :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Can Zsh do this for me?
  2003-09-02 12:38 ` Alexey Tourbin
  2003-09-02 13:07   ` Peter Stephenson
@ 2003-09-02 19:22   ` DervishD
  1 sibling, 0 replies; 8+ messages in thread
From: DervishD @ 2003-09-02 19:22 UTC (permalink / raw)
  To: Alexey Tourbin; +Cc: Zsh

    Hi Alexey :)

 * Alexey Tourbin <at@altlinux.ru> dixit:
> >     I'm writing a command to kill a process by name, not by PID, just
> > like 'pidof' but without using 'pidof' ;))) It's pretty easy using
> Do you have killall(1)?

    That's the point, I don't have those binaries (it's a long story)
and I would prefer not to install them if I can avoid it (and seems
like I can avoid it...). Moreover, there are *two* killall binaries
lurking around in Linux. One of them does what its name suggests, and
kills all running processes (well, more or less...). The other one
kills a process by name, not by PID.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Can Zsh do this for me?
  2003-09-02 13:30 ` Jason Price
@ 2003-09-02 19:57   ` DervishD
  0 siblings, 0 replies; 8+ messages in thread
From: DervishD @ 2003-09-02 19:57 UTC (permalink / raw)
  To: Jason Price; +Cc: Zsh

    Hi Jason :)

 * Jason Price <jprice@cyberbuzz.gatech.edu> dixit:
> BTW: if you're re-writing linux PS as a shell script to learn a lot of
> linux and zsh internals, go right ahead.  If you're just annoyed by how it
> works, take a long look through the man page.

    I've done. Hundreds of times. And I'm still feared with the
number of options... Well, I must say that my procps comes from a
Debian 1.3.1, and since then obviously it has gone better.

> It's amazingly powerful and flexable.

    IMHO, is amazingly bloated. Currently, new versions of procps are
cleaner, faster, etc... but much of the bloat remains. The cause is
not procps, nor Albert, but the compatibility with all flavors of ps
out there: BSD, SysV, etc...

> It looks like you were using the BSD flavor of args.

    Yes, is a question of habits (bad ones, I suppose). I have been
using Linux since 1994 or so, and I've always used BSD flavor of ps.

> ps.  The only thing that competes with ls for number of options.

    You are definitely true ;))))

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-09-02 19:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-02 12:08 Can Zsh do this for me? DervishD
2003-09-02 12:25 ` Oliver Kiddle
2003-09-02 19:21   ` DervishD
2003-09-02 12:38 ` Alexey Tourbin
2003-09-02 13:07   ` Peter Stephenson
2003-09-02 19:22   ` DervishD
2003-09-02 13:30 ` Jason Price
2003-09-02 19:57   ` DervishD

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).