I have a Shell Scritp named "Statistics" which has a Infinate Wille Loop Running
I want to restart this Srcipt "Statistics" when i try to run other srcipt Ex "ABC"
so i want to kill the "Statistics" script in "ABC"
so for this I what to know the PID for that Script "Statistics" which is running continusly
When i try ps -ef | grep Statistics it does not give me any thing
How do i know the PID for the script "Statictics" ?
vino
2
Does 'Statistics' appear in the ps -ef list at all ? Or did you get the spelling wrong ?
As a side note, if Statistics is running, then you would have two rows of result when you issue ps -ef | grep Statistics. You might want to switch to
ps -ef | grep 'tatistics'
Ya Vino
I does not appear in ps -ef list
i dont know if a process is created for a srcipt running
i yes with what name?
Consider this:
$ echo "while :;do sleep 10; done" > Statistics
$ chmod +x Statistics
$ ./Statistics &
[1] 13719
ess038$ ps -p 13719
PID TTY TIME CMD
13719 pts/1 0:00 bash
$ kill -9 13719
$
[1]+ Killed ./Statistics
So you can modify your script as:
$ echo "echo \$\$ > Statistics.pid" > Statistics
$ echo "while :;do sleep 10; done" >> Statistics
$ ./Statistics &
[1] 14336
$ cat Statistics.pid
14336
$ kill -9 $(<Statistics.pid)
$
[1]+ Killed ./Statistics
The Code u gave starts a back ground process and immeditly kills it
My requirement goes this way
when i run a script say "ABC"
1-- it should stop the .Statistics script by killing the previously running .Statistics
2-- then restart the .Statistics script again
You have to write it yourself ...
Anyway, you could use something like this:
$ cat Statistics
echo $$ > Statistics.pid
while :;do sleep 10; done
$ cat ABC
kill -9 $(<Statistics.pid)
./Statistics
I have found some alternative
if i give
#!/bin/ksh
as the first statment in script
then the process gets submitted with the scripts name as Process name
then i grep for the script name from ps -ef and that solves the problem
Thanks for Everything
... and, of course, "grep"-ing the pid from ps will be less efficient.