Re: why could not find process? (301 Views)
Reply
Occasional Visitor
faust2008
Posts: 2
Registered: ‎08-09-2004
Message 1 of 5 (301 Views)
Accepted Solution

why could not find process?

Hi , export,

My platform is hp 11i.
I user timer.sh to start a program timer 热repeatly. the content of timer.sh is:

while(true)
do
if [ "`ps -ef|grep './timer '|grep -v grep`" = "" ]
then
./timer IBSS2 WSNADRR=//132.97.9.71:2888 >/dev/null 2>&1
sleep 32
else
sleep 32
fi
done

I start timer.sh in this way:
ksh
timer.sh &
exit
but when I use ps -fe|grep timer.sh ,
I find nothing ,I think the timer.sh should stay alive all the time. in fact the timer exec repeatly.
can anyone tell me why ?
thx a lot


Honored Contributor
RAC_1
Posts: 5,920
Registered: ‎03-21-2002
Message 2 of 5 (301 Views)

Re: why could not find process?

Does your program (timer) start manually? Also, you check check if a processes is running or not by sending signal 0 to it.

Also, whay all that grep? If you know process name (exact process name), then you can do as follows.

proc_pid=$(UNIX95= ps -C "timer" -o pid|grep -v 'PID)

kill -o ${proc_pid} || "start_your_program"
There is no substitute to HARDWORK
Honored Contributor
Jonathan Fife
Posts: 256
Registered: ‎07-19-2006
Message 3 of 5 (301 Views)

Re: why could not find process?

Does timer.sh invoke a new shell (ie. #!/bin/ksh)?

If not, it will just execute the contents of the script and not show the script name in a process list. If you do a ps -fe | grep sleep I bet you'll see your sleep 32 processes there.

$cat timer.sh
while(true)
do
sleep 5
done
$./timer.sh &
[1] 13012
$ps -ef | grep timer
fifejj 13016 12414 0 11:23:59 pts/ta 0:00 grep timer
$ps -ef | grep 13012
fifejj 13012 12414 1 11:23:55 pts/ta 0:00 -ksh
fifejj 13018 13012 1 11:24:00 pts/ta 0:00 sleep 5

and now invoking a new shell:

$cat timer.sh
#!/bin/ksh

while(true)
do
sleep 5
done
$./timer.sh &
[1] 13028
$ps -ef | grep timer
fifejj 13032 12414 1 11:24:28 pts/ta 0:00 grep timer
fifejj 13028 12414 3 11:24:26 pts/ta 0:00 /bin/ksh ./timer.sh



Decay is inherent in all compounded things. Strive on with diligence
Occasional Visitor
faust2008
Posts: 2
Registered: ‎08-09-2004
Message 4 of 5 (301 Views)

Re: why could not find process?

Jonathan, you are right , I can grep sleep 32. I just don't understand why can not grep
timer.sh
what is the diference betwen ksh and #!/bin/ksh?
if I use #!/bin/ksh , it seem that I can grep ./timer.sh ?

we have servral programs , all exex like
this :
ksh
program1 $
exit
ksh
program2 $
exit
I donot know why they exec like this.
can I exec them like this? :
#!/bin/ksh
program1 $
program2 $
exit
thanks a lot





Honored Contributor
Jonathan Fife
Posts: 256
Registered: ‎07-19-2006
Message 5 of 5 (301 Views)

Re: why could not find process?

Putting #!/bin/ksh at the beginning of the script will just invoke a new shell. Otherwise, the commands will run in the current shell.

It should be fine to run them in an executable script as

#!/bin/ksh
program1
program2
exit

Jon
Decay is inherent in all compounded things. Strive on with diligence
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.