Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write PID to a File 1

Status
Not open for further replies.

weweber3

MIS
Mar 4, 2004
17
US
I need to be able to kick this process off at 12am and let it run until 6am and then kill the process. The process is a DB2 process, which is irrelevany. In order to kill that process I need the process id. I would like to kick off this command and append the PID to a text file for reference. Anyone have any idea how to do this?

Thanks.
 
If you know the name of the process, the complete path name then type pidof {process name}

pidof sshd

and the pid number or numbers will return.


You then could redirect that to a file

pidof sshd > sshd.pid


Or you could do something like this

#!/bin/sh

PIDS=`ps -ax | grep {process} | awk '{print $1}'`
LOG=/var/log/my_log_file

for i in $PIDS
do
echo "Killing pid $i" >> $LOG
kill -9 $i
done


Try something like that.
 
take a look to the special variable [tt]$$[/tt] in your shell (ksh at least). Example:

[tt]my_process='echo $$'
killmyself='kill -9 $$'[/tt]
 
As jstreich said, try running in a script. I use these scripts to do this:

Code:
# Start the program
/path/to/binary
pid=$!
disown $pid
echo $pid > /var/run/binary

And this to kill it afterwards:

Code:
# Grab the pid and kill it
pid=`cat /var/run/binary`
kill $pid

You'll have to do some editing of course. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top