From Wiki-UX.info

Wiki-UX / How to save process id number
Jump to: navigation, search

How to save process id number

Abstract

The following document demostrates how to capture the process id (pid) number of an application on it's startup script.

Contents


The "fakeproc" application

This script simulates an system application. It basically keeps a date command sending the system date to /dev/null and sleeping for 30 seconds. Current system aplication will probably do something less trivial!

while true
do
date > /dev/null
sleep 30
done

The start script

This "start" up script captures the "fakeproc" pid number using POSIX shell $! variable into the fakeproc.pid file every time that is executed.

# Starts the fakeproc process
PID="-1"
$(pwd)/fakeproc &
PID=$!
echo "fakeproc pid $PID" > $(pwd)/fakeproc.pid

Kill "fakeproc" process

To kill "fakeproc" send a TERM or KILL signal using the captured pid number.

# kill $(awk '{print $3}' fakeproc.pid)

or

# kill -9 $(awk '{print $3}' fakeproc.pid)

Reference

Authors

This page was last modified on 20 April 2011, at 17:01. This page has been accessed 1,485 times.