Loading ...
Sorry, an error occurred while loading the content.

Finding a process

Expand Messages
  • Godwin Stewart
    Hi, Is there a Perl way to find out if another (Linux) process of which I know the PID is running? And, better still, is it possible to get the command line of
    Message 1 of 6 , Dec 3, 2001
    • 0 Attachment
      Hi,

      Is there a Perl way to find out if another (Linux) process of which I know
      the PID is running? And, better still, is it possible to get the command
      line of that process?

      When my program starts up, it forks and dumps a file containing the PID of
      the new process into its working directory, and then the parent process
      exits, in effect letting the child perform a "setsid" and then run as a
      daemon. Basically I want to stop a second copy of this program being
      started. Due to factors beyond my control, the system on which it will be
      running is rather unstable at the minute and can crash, leaving a stale PID
      file on the disk.

      So, unless I can find out whether any pre-existent PID file is stale or
      current (and belonging to my program), I won't know whether to abort
      straight away or to continue.

      Any ideas out there?

      TIA

      --
      ____________________________________________
      | G. Stewart -- gstewart@... |
      | Port de Pontille, FR-37500 CHINON, FRANCE. |
      ____________________________________________
    • Trap 13
      ... kill 0 to check the process Not a Perl way : parsing the ps output ... -- Ce qu il y a d enivrant dans le mauvais goût, c est le plaisir aristocratique de
      Message 2 of 6 , Dec 4, 2001
      • 0 Attachment
        On Mon, Dec 03, 2001 at 10:46:49PM +0100, Godwin Stewart wrote:
        > Hi,
        >
        > Is there a Perl way to find out if another (Linux) process of which I know
        > the PID is running? And, better still, is it possible to get the command
        > line of that process?

        kill 0 to check the process

        Not a Perl way : parsing the ps output

        >
        > When my program starts up, it forks and dumps a file containing the PID of
        > the new process into its working directory, and then the parent process
        > exits, in effect letting the child perform a "setsid" and then run as a
        > daemon. Basically I want to stop a second copy of this program being
        > started. Due to factors beyond my control, the system on which it will be
        > running is rather unstable at the minute and can crash, leaving a stale PID
        > file on the disk.
        >
        > So, unless I can find out whether any pre-existent PID file is stale or
        > current (and belonging to my program), I won't know whether to abort
        > straight away or to continue.
        >
        > Any ideas out there?
        >
        > TIA
        >
        > --
        > ____________________________________________
        > | G. Stewart -- gstewart@... |
        > | Port de Pontille, FR-37500 CHINON, FRANCE. |
        > ____________________________________________
        >
        >
        > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
        >
        > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        >
        >
        >

        --
        Ce qu'il y a d'enivrant dans le mauvais goût, c'est le plaisir
        aristocratique de déplaire.

        Charles Baudelaire - Mon coeur mis à nu.
      • Godwin Stewart
        ... C est bien ce qu il me semblait. Je pense que j aurai plus vite fait de virer le verrou obsolète au démarrage de la bécane. Merci quand-même ;o) -- ...
        Message 3 of 6 , Dec 4, 2001
        • 0 Attachment
          On Tue, 4 Dec 2001 22:13:49 +0100, Trap 13 <bugbuilder@...> wrote:

          > kill 0 to check the process
          >
          > Not a Perl way : parsing the ps output

          C'est bien ce qu'il me semblait. Je pense que j'aurai plus vite fait de
          virer le verrou obsolète au démarrage de la bécane.

          Merci quand-même ;o)

          --
          ____________________________________________
          | G. Stewart -- gstewart@... |
          | Port de Pontille, FR-37500 CHINON, FRANCE. |
          ____________________________________________
        • Godwin Stewart
          ... ?????? Let me guess, this is an AltaVista BabelFish translation . Right? At least this was just about readable. BabelFish has a nasty habit of translating
          Message 4 of 6 , Dec 5, 2001
          • 0 Attachment
            On Tue, 4 Dec 2001 21:34:59 -0800 (PST), John Mayson <kc4vjo@...> wrote:

            >
            > Il est facile pour vous dire ce. ;-)

            ??????

            Let me guess, this is an AltaVista BabelFish "translation". Right?

            At least this was just about readable. BabelFish has a nasty habit of
            translating word for word, sometimes making the end result pretty laughable.

            Since it was a Frenchman who replied to me I replied in French, and since
            I've been living in France for almost 20 years I speak the language
            fluently. I guess I should have translated what I said:

            "That's what I thought. I think it'll be quicker for me to delete the stale
            lock file when the box starts up. Thanks anyway"

            --
            ____________________________________________
            | G. Stewart -- gstewart@... |
            | Port de Pontille, FR-37500 CHINON, FRANCE. |
            ____________________________________________
          • Michael Covi
            There s also the /proc file system. Each process has it s pid there as a directry and one of the files in the directry is cmdline. So if your pid is 77 then
            Message 5 of 6 , Dec 8, 2001
            • 0 Attachment
              There's also the /proc file system. Each process has it's pid there as a
              directry and one of the files in the directry is cmdline.

              So if your pid is 77 then

              /proc/77/cmdline should exist and have the name of your process in it.

              On Mon, 3 Dec 2001, Godwin Stewart wrote:

              > Hi,
              >
              > Is there a Perl way to find out if another (Linux) process of which I know
              > the PID is running? And, better still, is it possible to get the command
              > line of that process?
              >
              > When my program starts up, it forks and dumps a file containing the PID of
              > the new process into its working directory, and then the parent process
              > exits, in effect letting the child perform a "setsid" and then run as a
              > daemon. Basically I want to stop a second copy of this program being
              > started. Due to factors beyond my control, the system on which it will be
              > running is rather unstable at the minute and can crash, leaving a stale PID
              > file on the disk.
              >
              > So, unless I can find out whether any pre-existent PID file is stale or
              > current (and belonging to my program), I won't know whether to abort
              > straight away or to continue.
              >
              > Any ideas out there?
            • Godwin Stewart
              On Sun, 9 Dec 2001 01:00:26 +1100 (EST), Michael Covi ... That s perfect! The /proc filesystem is enabled in the kernel of the machine which will be running my
              Message 6 of 6 , Dec 8, 2001
              • 0 Attachment
                On Sun, 9 Dec 2001 01:00:26 +1100 (EST), Michael Covi
                <thebaron22@...> wrote:

                > There's also the /proc file system. Each process has it's pid there as a
                > directry and one of the files in the directry is cmdline.

                That's perfect!

                The /proc filesystem is enabled in the kernel of the machine which will be
                running my program, so this should work fine.

                Many thanks!

                --
                ____________________________________________
                | G. Stewart -- gstewart@... |
                | Port de Pontille, FR-37500 CHINON, FRANCE. |
                ____________________________________________
              Your message has been successfully submitted and would be delivered to recipients shortly.