Linux – Get PID of process started in screen by su

bashgnu-screenlinuxpidshell-script

i have a simple script that starts quassel-core in a screen session as different user!
The script is:

#!/bin/sh
su ircc -c 'screen -dmS quassel /home/ircc/quassel/quassel-core'

I want to start and stop this in an debian init.d script using start-stop-daemon
What is the best way to get the PID of quassel-core (or of the screen, that should work too) and store it in a file?
At the moment i use:

pidof quassel-core > /var/run/quasselcore.pid

but that will fail if some other user starts quassel-core.

Best Answer

It seems like you are happy just to kill a named screen session belonging to your user, and not really interested in the pid. In that case, with a screen named "quassel", you can run

screen -S quassel -X quit

which as per the manual will

Kill all windows and terminate screen.

Only screens owned by you are affected.

Related Question