Is it technically possible to give Python option of naming process ofrunning script?

Discussion in 'Python' started by xliiv, Mar 14, 2012.

  1. xliiv

    xliiv Guest

    Like the topic.. .
    I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what.
     
    xliiv, Mar 14, 2012
    #1
    1. Advertising

  2. Re: Is it technically possible to give Python option of namingprocess of running script?

    On Thu, Mar 15, 2012 at 1:43 AM, xliiv <> wrote:
    > Like the topic.. .
    > I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what.


    I've no idea if it's even possible on Windows. On Linux, what you want
    is the prctl function, which (AFAIK) isn't directly available.

    Google is your friend, though. Question's already been asked on Stack
    Overflow and such, and has a few answers. Nothing that looks
    cut-and-dried ready, but several that might work. Look for 'prctl' and
    'PR_SET_NAME', which are the C-level function and constant that do the
    job; a cursory examination of PyPI shows a module with prctl in the
    name, so that may be of value.

    ChrisA
     
    Chris Angelico, Mar 14, 2012
    #2
    1. Advertising

  3. Re: Is it technically possible to give Python option of namingprocess of running script?

    On 2012-03-14, Chris Angelico <> wrote:
    > On Thu, Mar 15, 2012 at 1:43 AM, xliiv <> wrote:
    >> Like the topic.. .
    >> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what.

    >
    > I've no idea if it's even possible on Windows. On Linux, what you want
    > is the prctl function, which (AFAIK) isn't directly available.
    >
    > Google is your friend, though. Question's already been asked on Stack
    > Overflow and such, and has a few answers. Nothing that looks
    > cut-and-dried ready, but several that might work.


    The question of how to set the application name comes up somewhat
    regularly. It would be awfully nice if there was a way for python
    applications to set their application name. It's especially useful
    for daemons, and makes it much easier when you can kill them by name
    instead of having to look up the PID.

    It seems like an excellent thing to add to the "os" module.

    > Look for 'prctl' and 'PR_SET_NAME', which are the C-level function
    > and constant that do the job; a cursory examination of PyPI shows a
    > module with prctl in the name, so that may be of value.


    --
    Grant Edwards grant.b.edwards Yow! TONY RANDALL! Is YOUR
    at life a PATIO of FUN??
    gmail.com
     
    Grant Edwards, Mar 14, 2012
    #3
  4. xliiv

    Terry Reedy Guest

    Re: Is it technically possible to give Python option of naming processof running script?

    On 3/14/2012 12:02 PM, Grant Edwards wrote:

    > It seems like an excellent thing to add to the "os" module.


    If 'prctl' is a standard POSIX system call, then it should be a
    candidate for inclusion in the os module if someone opens a tracker
    enhancement issue and presents an argument in favor.

    --
    Terry Jan Reedy
     
    Terry Reedy, Mar 14, 2012
    #4
  5. RE: Is it technically possible to give Python option of namingprocess of running script?

    > > It seems like an excellent thing to add to the "os" module.

    >
    > If 'prctl' is a standard POSIX system call, then it should be a
    > candidate for inclusion in the os module if someone opens a tracker
    > enhancement issue and presents an argument in favor.



    I think this request was already denied: http://bugs.python.org/issue5672

    Ramit


    Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
    712 Main Street | Houston, TX 77002
    work phone: 713 - 216 - 5423

    --

    This email is confidential and subject to important disclaimers and
    conditions including on offers for the purchase or sale of
    securities, accuracy and completeness of information, viruses,
    confidentiality, legal privilege, and legal entity disclaimers,
    available at http://www.jpmorgan.com/pages/disclosures/email.
     
    Prasad, Ramit, Mar 14, 2012
    #5
  6. RE: Is it technically possible to give Python option of namingprocess of running script?


    > > > It seems like an excellent thing to add to the "os" module.

    > >
    > > If 'prctl' is a standard POSIX system call, then it should be a
    > > candidate for inclusion in the os module if someone opens a tracker
    > > enhancement issue and presents an argument in favor.

    >
    >
    > I think this request was already denied: http://bugs.python.org/issue5672


    Also take a look at: https://github.com/dvarrazzo/py-setproctitle
    Though since they just create a Named Object in Windows, I am not sure
    it would work for something like killall.


    Ramit


    Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
    712 Main Street | Houston,TX 77002
    work phone: 713 - 216 - 5423

    --

    This email is confidential and subject to important disclaimers and
    conditions including on offers for the purchase or sale of
    securities, accuracy and completeness of information, viruses,
    confidentiality, legal privilege, and legal entity disclaimers,
    available at http://www.jpmorgan.com/pages/disclosures/email.
     
    Prasad, Ramit, Mar 14, 2012
    #6
  7. Re: Is it technically possible to give Python option of naming process of running script?

    Terry Reedy <> writes:

    > On 3/14/2012 12:02 PM, Grant Edwards wrote:
    >
    >> It seems like an excellent thing to add to the "os" module.

    >
    > If 'prctl' is a standard POSIX system call, then it should be a
    > candidate for inclusion in the os module if someone opens a tracker
    > enhancement issue and presents an argument in favor.


    It's not. The man page says "This call is Linux-specific."

    -- Alain.
     
    Alain Ketterlin, Mar 14, 2012
    #7
  8. xliiv

    Dave Angel Guest

    Re: Is it technically possible to give Python option of naming processof running script?

    On 03/14/2012 01:27 PM, Prasad, Ramit wrote:
    >>>> It seems like an excellent thing to add to the "os" module.
    >>> If 'prctl' is a standard POSIX system call, then it should be a
    >>> candidate for inclusion in the os module if someone opens a tracker
    >>> enhancement issue and presents an argument in favor.

    >>
    >> I think this request was already denied: http://bugs.python.org/issue5672

    > Also take a look at: https://github.com/dvarrazzo/py-setproctitle
    > Though since they just create a Named Object in Windows, I am not sure
    > it would work for something like killall.
    >
    >


    There is/was a project called exemaker for Windows. (see Pypi for
    link). I don't use Windows any more, but it was a nice trick, when it
    worked. Not all python scripts could be wrapped in it, but basically it
    let you wrap a python script in a tiny Windows program which launched
    the usual python dll's. You could call it anything you liked, and
    that's what the task manager saw as the process name.




    --

    DaveA
     
    Dave Angel, Mar 15, 2012
    #8
  9. xliiv

    xliiv Guest

    Re: Is it technically possible to give Python option of namingprocess of running script?

    > >> Like the topic.. .
    > >> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what.

    > >
    > > I've no idea if it's even possible on Windows. On Linux, what you want
    > > is the prctl function, which (AFAIK) isn't directly available.
    > >
    > > Google is your friend, though. Question's already been asked on Stack
    > > Overflow and such, and has a few answers. Nothing that looks
    > > cut-and-dried ready, but several that might work.

    >
    > The question of how to set the application name comes up somewhat
    > regularly. It would be awfully nice if there was a way for python
    > applications to set their application name. It's especially useful
    > for daemons, and makes it much easier when you can kill them by name
    > instead of having to look up the PID.
    >
    > It seems like an excellent thing to add to the "os" module.
    >
    > > Look for 'prctl' and 'PR_SET_NAME', which are the C-level function
    > > and constant that do the job; a cursory examination of PyPI shows a
    > > module with prctl in the name, so that may be of value.



    I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow.
    The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible?
     
    xliiv, Mar 15, 2012
    #9
  10. xliiv

    xliiv Guest

    Re: Is it technically possible to give Python option of namingprocess of running script?

    > >> Like the topic.. .
    > >> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what.

    > >
    > > I've no idea if it's even possible on Windows. On Linux, what you want
    > > is the prctl function, which (AFAIK) isn't directly available.
    > >
    > > Google is your friend, though. Question's already been asked on Stack
    > > Overflow and such, and has a few answers. Nothing that looks
    > > cut-and-dried ready, but several that might work.

    >
    > The question of how to set the application name comes up somewhat
    > regularly. It would be awfully nice if there was a way for python
    > applications to set their application name. It's especially useful
    > for daemons, and makes it much easier when you can kill them by name
    > instead of having to look up the PID.
    >
    > It seems like an excellent thing to add to the "os" module.
    >
    > > Look for 'prctl' and 'PR_SET_NAME', which are the C-level function
    > > and constant that do the job; a cursory examination of PyPI shows a
    > > module with prctl in the name, so that may be of value.



    I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow.
    The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible?
     
    xliiv, Mar 15, 2012
    #10
  11. xliiv

    Dave Angel Guest

    Re: Is it technically possible to give Python option of naming processof running script?

    On 03/15/2012 03:26 AM, xliiv wrote:
    >>>> Like the topic.. .
    >>>> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what.

    >>

    >
    > I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow.
    > The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible?


    How about simply using cp to copy the python executable, run chmod +x on
    it, and run that one? Then ps would list it as the new name, not as python.

    i tried it on /usr/bin/python2.7 but I see no reason the same
    approach won't work on 3.x Note, I copied it to a new name in the same
    directory, which may be important. or not.

    --

    DaveA
     
    Dave Angel, Mar 15, 2012
    #11
  12. Re: Is it technically possible to give Python option of namingprocess of running script?

    On 2012-03-15, Dave Angel <> wrote:
    > On 03/15/2012 03:26 AM, xliiv wrote:
    >>>>> Like the topic.. .
    >>>>> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what.
    >>>

    >>
    >> I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow.
    >> The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible?

    >
    > How about simply using cp to copy the python executable, run chmod +x on
    > it, and run that one? Then ps would list it as the new name, not as python.


    That's rather a waste of memory. Better to use a link. That way the
    executable can still be shared by multiple programs and won't be
    duplicated in memory.

    > i tried it on /usr/bin/python2.7 but I see no reason the same
    > approach won't work on 3.x Note, I copied it to a new name in the same
    > directory, which may be important. or not.


    Seems like an awfully obtuse way of doing things -- I don't really
    want to have 15 different copies of Python (or even links), and it
    requires root privleges every time you want to run a Python program
    with the "correct" name.

    --
    Grant Edwards grant.b.edwards Yow! Can I have an IMPULSE
    at ITEM instead?
    gmail.com
     
    Grant Edwards, Mar 15, 2012
    #12
  13. xliiv

    Dave Angel Guest

    Re: Is it technically possible to give Python option of naming processof running script?

    On 03/15/2012 02:39 PM, Grant Edwards wrote:
    > On 2012-03-15, Dave Angel<> wrote:
    >> On 03/15/2012 03:26 AM, xliiv wrote:
    >>>>>> Like the topic.. .
    >>>>>> I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what.
    >>> I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow.
    >>> The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible?

    >> How about simply using cp to copy the python executable, run chmod +x on
    >> it, and run that one? Then ps would list it as the new name, not as python.

    > That's rather a waste of memory. Better to use a link. That way the
    > executable can still be shared by multiple programs and won't be
    > duplicated in memory.
    >
    >> i tried it on /usr/bin/python2.7 but I see no reason the same
    >> approach won't work on 3.x Note, I copied it to a new name in the same
    >> directory, which may be important. or not.

    > Seems like an awfully obtuse way of doing things -- I don't really
    > want to have 15 different copies of Python (or even links), and it
    > requires root privleges every time you want to run a Python program
    > with the "correct" name.
    >


    Good point about using a link. I was trying to make something that
    would probably also work in Windows. As for the needing of root
    privileges, that's only for those programs you need to be able to
    identify with ps, and only one time for each.

    Anyway, it's a response to a specific need, which I don't share, and it
    was my second suggestion, not first.



    --

    DaveA
     
    Dave Angel, Mar 16, 2012
    #13
  14. Re: Is it technically possible to give Python option of namingprocess of running script?

    On Fri, Mar 16, 2012 at 5:39 AM, Grant Edwards <> wrote:
    > Seems like an awfully obtuse way of doing things -- I don't really
    > want to have 15 different copies of Python (or even links), and it
    > requires root privleges every time you want to run a Python program
    > with the "correct" name.


    Why do you need root? Can't you copy / link into your own home directory?

    I may have misunderstood something here.

    ChrisA
     
    Chris Angelico, Mar 16, 2012
    #14
  15. xliiv

    xliiv Guest

    Re: Is it technically possible to give Python option of namingprocess of running script?


    > > Seems like an awfully obtuse way of doing things -- I don't really
    > > want to have 15 different copies of Python (or even links), and it
    > > requires root privleges every time you want to run a Python program
    > > with the "correct" name.

    >
    > Why do you need root? Can't you copy / link into your own home directory?
    >
    > I may have misunderstood something here.
    >
    > ChrisA


    It's nice walkaround for now and for linux. But how about my question and future? :)
     
    xliiv, Mar 16, 2012
    #15
  16. xliiv

    xliiv Guest

    Re: Is it technically possible to give Python option of namingprocess of running script?


    > > Seems like an awfully obtuse way of doing things -- I don't really
    > > want to have 15 different copies of Python (or even links), and it
    > > requires root privleges every time you want to run a Python program
    > > with the "correct" name.

    >
    > Why do you need root? Can't you copy / link into your own home directory?
    >
    > I may have misunderstood something here.
    >
    > ChrisA


    It's nice walkaround for now and for linux. But how about my question and future? :)
     
    xliiv, Mar 16, 2012
    #16
  17. Re: Is it technically possible to give Python option of namingprocess of running script?

    On 2012-03-16, Chris Angelico <> wrote:
    > On Fri, Mar 16, 2012 at 5:39 AM, Grant Edwards <> wrote:
    >> Seems like an awfully obtuse way of doing things -- I don't really
    >> want to have 15 different copies of Python (or even links), and it
    >> requires root privleges every time you want to run a Python program
    >> with the "correct" name.

    >
    > Why do you need root? Can't you copy / link into your own home directory?


    I was thinging about daemons and system-type stuff.

    One possible problem with linking from one's home directory is that
    home directories are often on different filesystems than /usr/bin (or
    wherever python is). Using a symlink doesn't work, the process name
    still ends up as python2.6 (or whatever the real binary is called).

    --
    Grant Edwards grant.b.edwards Yow! Where do your SOCKS
    at go when you lose them in
    gmail.com th' WASHER?
     
    Grant Edwards, Mar 16, 2012
    #17
  18. RE: Is it technically possible to give Python option of namingprocess of running script?

    > I was thinging about daemons and system-type stuff.

    >
    > One possible problem with linking from one's home directory is that
    > homedirectories are often on different filesystems than /usr/bin (or
    > wherever python is). Using a symlink doesn't work, the process name
    > still ends up as python2.6 (or whatever the real binary is called).



    Try a hardlink instead of symlink? It seems to work for me.


    Ramit


    Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
    712 Main Street | Houston, TX 77002
    work phone: 713 - 216 - 5423

    --

    This email is confidential and subject to important disclaimers and
    conditions including on offers for the purchase or sale of
    securities, accuracy and completeness of information, viruses,
    confidentiality, legal privilege, and legal entity disclaimers,
    available at http://www.jpmorgan.com/pages/disclosures/email.
     
    Prasad, Ramit, Mar 16, 2012
    #18
  19. Re: Is it technically possible to give Python option of namingprocess of running script?

    On 2012-03-16, Prasad, Ramit <> wrote:
    >
    >> One possible problem with linking from one's home directory is that
    >> home directories are often on different filesystems than /usr/bin (or
    >> wherever python is). Using a symlink doesn't work, the process name
    >> still ends up as python2.6 (or whatever the real binary is called).

    >
    > Try a hardlink instead of symlink? It seems to work for me.


    Not across different filesystems -- which was what I was talking
    about.

    --
    Grant Edwards grant.b.edwards Yow! As President I have
    at to go vacuum my coin
    gmail.com collection!
     
    Grant Edwards, Mar 16, 2012
    #19
  20. Re: Is it technically possible to give Python option of namingprocess of running script?

    On Wed, 2012-03-14 at 07:43 -0700, xliiv wrote:
    > Like the topic.. .
    > I use Python a lot, both Windows and Linux, and it's little weird to
    > have many python process without fast distinction which is what.


    I'm not sure of my interpretation of your problem but if you want to set
    the name of the running process in the process table, at least on
    LINUX/UNIX, you can use the procname module available via PyPI.



    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.18 (GNU/Linux)

    iEYEABECAAYFAk9t5ycACgkQLRePpNle04NyfwCdGGVuABLF15Ja8/HYhuPKvaO8
    7mMAnjrMxJ7n78RdLEr1aNlxya9j1SoY
    =+FT+
    -----END PGP SIGNATURE-----
     
    Adam Tauno Williams, Mar 24, 2012
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harman
    Replies:
    1
    Views:
    2,548
    Moiristo
    Jul 28, 2006
  2. grocery_stocker
    Replies:
    10
    Views:
    661
    Keith Thompson
    May 25, 2005
  3. Lax
    Replies:
    2
    Views:
    528
    Richard Tobin
    Apr 13, 2008
  4. sam
    Replies:
    11
    Views:
    1,224
    James Kanze
    Sep 12, 2008
  5. OwlHoot
    Replies:
    0
    Views:
    139
    OwlHoot
    Aug 23, 2007
Loading...

Share This Page