Need to know rhe PID for the Shell Script running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to know rhe PID for the Shell Script running
# 1  
Old 01-25-2007
Need to know rhe PID for the Shell Script running

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" ?
# 2  
Old 01-25-2007
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
Code:
ps -ef | grep '[S]tatistics'

# 3  
Old 01-25-2007
statistics does not appear in ps -ef list

Quote:
Originally Posted by vino
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
Code:
ps -ef | grep '[S]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?
# 4  
Old 01-25-2007
Quote:
Originally Posted by pbsrinivas
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" ?
Consider this:

Code:
$ 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:

Code:
$ 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

# 5  
Old 01-25-2007
That was great piece of code but..

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
# 6  
Old 01-25-2007
Quote:
Originally Posted by pbsrinivas
[...]
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:

Code:
$ cat Statistics
echo $$ > Statistics.pid
while :;do sleep 10; done

$ cat ABC
kill -9 $(<Statistics.pid)
./Statistics

# 7  
Old 01-25-2007
Thanks for that process

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to report file size, pid and also kill the process

Hi All, Looking for a quick LINUX shell script which can continuously monitors the flle size, report the process which is creating a file greater than certain limit and also kill that process. Can someone please help me on this? (4 Replies)
Discussion started by: vasavimacherla
4 Replies

2. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

3. Shell Programming and Scripting

kill PID running in background in for loop

Guys, can you help me in killing the process which is running in back ground under for loop I am not able to find the PID using ps -afx|grep <word in command I entered> (1 Reply)
Discussion started by: mohan_xunil
1 Replies

4. Shell Programming and Scripting

Check process running Status with PID

Good day I am fairly new to Shell Scripting. I want a script to check if a process is up by checking the process's PID and then return a value for when it's running which would be 0. If it isn't running it should give any other value that 0. Any Help is appreciated Regards (9 Replies)
Discussion started by: 1nsyz1on
9 Replies

5. AIX

Having problem with executing shell script to get the pid details!

Hello Everyone, I am new to shell scripting and also i am very new to AIX machine I have a question. I have shell script which contains the follwing "ps -e |grep $1 echo $2" i run this schell script by doing this ./startSehllscript 3444 passed with two parameters . Accroiding my... (4 Replies)
Discussion started by: swati
4 Replies

6. Shell Programming and Scripting

shell script for getting pid of spawn processes from shell

Hi, I am new this forum. I request you peoples help in understanding and finding some solution to my problem. Here it goes: I need to perform this set of actions by writing a shell script. I need to read a config file for the bunch of processes to execute. I need to fecth the pid of... (4 Replies)
Discussion started by: sachin4sachi
4 Replies

7. UNIX for Advanced & Expert Users

delete all PID that running by UID ??

Hi experts, How can I delete the process running by particular UID. For an example- I want to delete all PID that running by UID- purple UID PID PPID C STIME TTY TIME CMD purple 120 122 0 Jan 17 ? 0:02 sched purple 234 235 0 Jan 17 ?... (6 Replies)
Discussion started by: thepurple
6 Replies

8. UNIX for Dummies Questions & Answers

How to find the details of the previously running process with PID

OS: Unix or Linux I (only) know the pid of the process which was running earlier (say 5 hrs back) but it is not running now. Is there a way I could find the details of that process? (atleast the name of the process). Please let me know. (2 Replies)
Discussion started by: vijay.d
2 Replies

9. Solaris

Running from Shell Vs running from RC script

Hi, i have a script which need to do behave differently when run as a startup process from init.d/ rc2.d script and when run manually from shell. How do i distinguish whether my script is run by init process or by shell?? Will the command /proc/$$/psinfo | grep "myscript" work well???... (2 Replies)
Discussion started by: vickylife
2 Replies

10. Linux

Display to PC via ssh/putty (RHE 5)

Hi all, I just installed Red Hat Enterprise and I would like to have the KDE/GNOME windows display to my PC. When I am root (via ssh, putty) I type startx but it fails. I'm not sure what has to be configured! Any help would be greatly appreciated. Thanks! (1 Reply)
Discussion started by: kjbaumann
1 Replies
Login or Register to Ask a Question