Results 1 to 3 of 3

Thread: Check process status by PID (running or dead)

  1. #1

    Default Check process status by PID (running or dead)

    I'm writing my own service, it should run an app:
    /usr/bin/socat PTY,link=/dev/ttyS0,raw,echo=0 tcp4:192.168.1.105:7000
    And write it's PID to /var/run/socat1.pid.
    How can I check if my app is running with a given PID from file? I need this to restart my service on status check (if PID is dead).

    Thanks in advance!

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    29,804

    Default Re: Check process status by PID (running or dead)

    You can check with ps -p (and add other options to influence the ouput, see man ps). When it exists (return code) you could check the command (and more, depends on what you asked for as output) against what itshould be, because in theory the same PID is used again after cycling all of them.

    BTW, When you want a process to be automaticaly restarted when it finishes (for whatever reason), you could make an entry in /etc/inittab for it.
    Henk van Velden

  3. #3
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,683
    Blog Entries
    4

    Default Re: Check process status by PID (running or dead)

    If the pid is of running process there will be a directory at /proc/<pid>. You should double check that it is indeed the right process by looking at its command line, by reading cmdline, one of the "files" in that directory.

    Better still, as hcvv said, use inittab to respawn the process when it exits.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •