My understanding is that it's generally a good idea to create a PID file for daemon processes and that startproc is a good way to start these daemons.

I know that startproc takes -i and -p arguments that refer to PID files but it doesn't create a PID file or update it with the ID of the daemon process that it starts. Echoing $! also doesn't give the right process identifier when startproc is used.

Does anyone have any advice as to how the PID of a daemon started with startproc can be elicited?

For what it's worth, I'm writing an rc script and want to start a JVM as a non-privileged user. I don't really want to give this user a login shell (so su -c "java ..." user is not an option) and I don't really want a root process hanging around while the daemon is running either (which rules out sudo -Eu user java ...). So, while I acknowledge that these are possible workarounds, I don't find either of them to be ideal. Please feel free, though, to correct me if my assumptions about these alternatives are wrong.

  • What's your OS? Is pidof available? The manpage for startproc on linux-tutorial.info/… doesn't know a -i option.
    – ott--
    Jun 12, 2013 at 2:58
  • I'm using OpenSuSE 11.4. pidof is available but given that there may be several JVMs running this may be tricky. Jun 12, 2013 at 9:35
  • You could compare the /proc/<pid>/cmdline of each pidof java to determine if such a daemon is already running. Note that the cmdline args are separated by \0 characters.
    – ott--
    Jun 12, 2013 at 10:59

2 Answers 2


Looks like nobody knows a way of doing this, then.

Instead, I just did what Tomcat basically does; write a shell script and invoke this from my service instead of invoking java directly.

This shell script also takes care of creating the PID file using echo $! after starting the JVM. For shutdown, I've written a similar script that checks this PID file and removes it after a successful shutdown. Both scripts are invoked using sudo -Eu $USER script_name.sh from the service.

Technically, this doesn't answer my question because the solution doesn't use startproc at all, but it works and avoids the cumbersome task of comparing command lines of running processes.


had the same problem, tried something:

PID=$(startproc -p $PID_FILE <some parameters>)
echo $PID  > $PID_FILE

and it worked ... tried it at SLES 11 SP4

but at SLES 12 everything works complete different :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.