Re: "pidof" on a process (which was ran by passing arguments from the command line)

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 07/04/05


Date: Sun, 3 Jul 2005 18:23:37 -0400

On 2005-07-03, amirbin@hotmail.com wrote:
> Hello,
>
> This question may be relevant to running "pidof" generally on processes
> which were run by passing an argument in the command line;
> To me it occurred with python.
>
> I am running a python script of xen.
>
> I want to be able to get the pid of that process by running "pidof".
>
> The command line for running the script is
> /xend start
> (but in fact it runs "python ./xend start" because the first line in
> "xend"
> script is "#!/usr/bin/env python".)
>
> ("python ./xend start"" is also what we get (among other processes)
> from
> ps -aux |grep python for that specific process I am talkng about).
>
>
> I want to be able to get the pid of that process by runnning "pidof".
>
>
> pidof "python ./xend start" gives nothing (in Bash and in Tcshell).
>
> pidof "python" gives 4 processes (one of them is the requested one).
>
> Moreover:
> 2502 is the process id of the wanted process.
> cat /proc/2502/cmdline
> gives:
> python./xendstart
>
>
> but trying pidof "python./xendstart" (also with one apostrphe or none
> at all)
> gave nothing.
>
>
> Also "pidof -x xend" does not help : it returns an empty string.
>
> Any idea?

   pidof obviously does not do what you want, so you need to use a
   different command (or combine pidof with other commands).

   What wrong with:

set -- $( ps ax | grep 'python.*\./xend' )
xend_pid=$1

-- 
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>


Relevant Pages

  • Re: IP connections
    ... produces output, depending on the command. ... start that script with the systemfunction. ... If you already have a favourite, such as perl, python, ... There are lots of complicated areas for experts, but most users can come a long way with the basics and the ready-made libraries. ...
    (comp.lang.c)
  • Re: IP connections
    ... produces output, depending on the command. ... start that script with the systemfunction. ... connect to the telnet port of the hi-tech device in the C ... recommend Python with the "telnetlib" library: ...
    (comp.lang.c)
  • Re: perl to python
    ... sed and perl can let you do all that quick command line stuff. ... into a full blown script. ... scripts, call it from the python interpreter, whatever I need. ... If I stick to the traditional unix approach, ...
    (comp.lang.python)
  • Re: newbie question
    ... Python is fun and it's easier to use a real OS to develop the programs, ... Grant it I am a command line junky, ... "The script can be given a executable mode, or permission, using the ... the above seems to me like you are useing windows. ...
    (comp.lang.python)
  • Re: Python executable
    ... Python scripts can be made directly ... >of the script and giving the file an executable mode. ... >$ chmod +x myscript.py ... >but I was given the bash: helloworld.py: command not found error. ...
    (comp.lang.python)