Checking before start and stop processes

Hi,

I have 2 start and stop sh.

Start sh
--------
This will start few processes.
Example code:

echo "start process : lgz200 /pipe=test_jobs"
nohup lgz200 /db=test/test1@test1 /pipe=test_jobs > ../log/lgz200_j.log &
echo "echo \"stop process (pid=$!): lgz200 /pipe=test_jobs\"" >> test_stop
echo "kill -9 $!" >> test_stop

echo "start process : lgz210 /pipe=test_jobs"
nohup lgz210 /db=test/test1@test1 > ../log/lgz210.log &
echo "echo \"stop process (pid=$!): lgz210 /pipe=test_jobs\"" >> test_stop
echo "kill -9 $!" >> test_stop

chmod 744 test_stop

exit 0

test_stop script (auto generated from start script)
--------------
echo "stop process (pid=155164): lgz200 /pipe=test_jobs"
kill -9 155164
echo "stop process (pid=128078): lgz210 /pipe=test_jobs"
kill -9 128078

Problem
-------
I wish to include checking in start and stop script like:
start - check if the process name is exist, if exist no action. else start a new process.
stop - a loop to check if the process still exists, if exist, kill it.

this 2 checking is to make sure there are no duplicate process that will be run concurently from start script and to make sure we will completely kill the process in stop script.

I am still beginner in unix, can anyone help me to show me some sample code to do the 2 checkings? Any other suggestion will be most welcomed.

Thank you very much for your help.

Regards,
weihann.

This might help you.

vino

thanks vino for the reply.

but how abt the making sure the process will be terminated successfully?

Get the process name. From that the process id.

Issue a kill -9 pid.

Possibly, a [<defunct>] process will still be there in the process list.

Removing that from your process list, requires something else. I do not have an idea as to what it is.

Some else could chip in at this time.

Vino