From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11941 invoked from network); 2 Sep 2003 12:24:14 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 2 Sep 2003 12:24:14 -0000 Received: (qmail 17663 invoked by alias); 2 Sep 2003 12:24:08 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19001 Received: (qmail 17652 invoked from network); 2 Sep 2003 12:24:08 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 2 Sep 2003 12:24:08 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [193.109.254.211] by sunsite.dk (MessageWall 1.0.8) with SMTP; 2 Sep 2003 12:24:6 -0000 X-VirusChecked: Checked X-Env-Sender: okiddle@yahoo.co.uk X-Msg-Ref: server-15.tower-36.messagelabs.com!1062505434!294251 X-StarScan-Version: 5.0.7; banners=-,-,- Received: (qmail 19398 invoked from network); 2 Sep 2003 12:23:54 -0000 Received: from iris.logica.co.uk (158.234.9.163) by server-15.tower-36.messagelabs.com with SMTP; 2 Sep 2003 12:23:54 -0000 Received: from gmcs3.local ([158.234.142.61]) by iris.logica.co.uk (8.12.3/8.12.3/Debian -4) with ESMTP id h82CNsHM031203; Tue, 2 Sep 2003 13:23:54 +0100 Received: from gmcs3.local (localhost [127.0.0.1]) by gmcs3.local (8.11.6/8.11.6/SuSE Linux 0.5) with ESMTP id h82CPsk02300; Tue, 2 Sep 2003 14:25:54 +0200 cc: Zsh X-VirusChecked: Checked X-StarScan-Version: 5.0.7; banners=.,-,- In-reply-to: <20030902120846.GA1636@DervishD> From: Oliver Kiddle References: <20030902120846.GA1636@DervishD> To: DervishD Subject: Re: Can Zsh do this for me? Date: Tue, 02 Sep 2003 14:25:54 +0200 Message-ID: <2298.1062505554@gmcs3.local> 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