I have created a simple script to start a process, but I am not sure how to add a stop step since the process is ran/stopped manually

Currently, to start the process, we use a single command line

omrun dssdaemon <a string to run>

Then, to stop it, the usual ps command

ps -ef | grep -i dssdaemon

kill -9 <PID>

I have gotten this far

# Priti's script to start dss daemon
pid=$(ps -ef | grep dssdaemon | grep -v grep | awk '{print $2}')
DSS_START=omrun dssdaemon <a string to run>

$DSS_START; sleep 15;
echo "DSS Daemons is running with PID[S] below" && $pid

The process has some limitation with using pidof, that is why I have created the awk string instead.

I could really use some help with adding a status and kill step.

Something like this

# status dss daemon
DSS Daemon is running with PID[S] below

# start dss daemon
DSS Daemon is started with PID[S] below

# stop dss daemon
DSS Daemon with PID[S] below were killed

1 Answer 1


Try to use killall or pkill tools. They do send a signal to the process just as kill does. But instead of pid, they look for the process by its name. And if you have several demons running - all of them would got the signal.

killall -9 dssdaemon
  • 2
    And may be try withouth the -9 to let the process terminate in an orderly fashion. The default SIGTERM should do the trick. Use SIGKILL (-9) as a last resort only.
    – markgraf
    Feb 23 at 7:31
  • Thank you for that, I have added it into the script. But I am not sure how to create a status/stop/start like that of systemctl to make this work in a single script. Feb 23 at 7:38
  • @PritiPatel You could try checking what arguments the script was invoked with using $# and shift Feb 23 at 13:38

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.