Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

why could not find process?

SOLVED
Go to solution
faust2008
Occasional Visitor

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


4 REPLIES
Highlighted
RAC_1
Honored Contributor

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
Jonathan Fife
Honored Contributor
Solution

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
faust2008
Occasional Visitor

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





Jonathan Fife
Honored Contributor

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