![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Inline function inside Classes | deepthi.s | High Level Programming | 1 | 08-22-2008 02:47 PM |
| value inside a function | trichyselva | Shell Programming and Scripting | 2 | 08-04-2008 08:44 AM |
| calling function inside awk | jisha | Shell Programming and Scripting | 2 | 04-14-2008 08:44 AM |
| remsh inside of while loop | joettacm | UNIX for Advanced & Expert Users | 1 | 12-07-2007 12:54 PM |
| read inside a while loop | dta4316 | UNIX for Dummies Questions & Answers | 3 | 05-21-2005 11:53 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Limiting the hanging of a function inside a loop
#! /bin/ksh
..(some lines are here..) for t in (LIST) do a=function($t) #here I want to wait till the function hangs for 5 secs else want to continue the loop for other values of t. done if [ $a = 1 ];then ............. fi ...... ...................... Suppose in this script; inside the for loop the function() hangs and unable return the result; then I want to wait till 5 secs. If the function hangs more than 5 secs for a certein variable then I want to continue the loop for the other variables in the LIST . plz help... |
|
||||
|
Quote:
Thanks a lot... I tried this as follows.. But it is not working.. ------------------------------------------------- #scipt name: fun f() { enccp -c mas start service_name -v -myPwd password # This is a IBM-encina command that is creating the sevice.. Which is hanging in this case } f & x=`jobs -p` { sleep 1; kill $x; } &>/dev/null & wait $x date OUTPUT: ------------------------------------------------------ [/home2/niroj_p]./fun Wed Sep 10 11:28:59 IST 2008 [/home2/niroj_p]starting service_name retrieving attributes of object service_name ... done setting up the server resources retrieving node object mars6 ... done creating file system path /var/opt/encina/local/subsys/encina/css6/server/service_name... exists retrieving encina server group name ... done retrieving encina administration organization ... done ................. ...........................Then it is hanging as usual |
|
||||
|
Can you kill it with a regular kill from the command line? If not, does it respond to other signals? (The default signal is SIGTERM, usually signal 15. Other useful signals to try are 2 = SIGINT and -- in utter desperation only -- 9 = SIGKILL.) Ctrl-C usually sends SIGINT.
|
|
||||
|
I tried this program with using for loop...
========================================= set -x f() { enccp -c mas start serv_nm -v -myPwd encina_admin } i=0 for i in 1 2 do f & x=`jobs -p` { sleep 1; kill -9 $x; } &>/dev/null & wait $x date i=`expr $i + 1` done =========================================== OUTPUT: ------------- [/home2/niroj_p]./fun + i=0 + + f + enccp -c mas start serv_nm -v -myPwd passwd + jobs -p x=0 + sleep 1 + 1> /dev/null + wait 0 + date Wed Sep 10 13:57:24 IST 2008 + + expr 1 + 1 i=2 + f + + enccp -c mas start serv_nm -v -myPwd passwd + + jobs -p x=0 0 0 + sleep 1 + 1> /dev/null + wait 0 0 0 + date Wed Sep 10 13:57:24 IST 2008 + + expr 2 + 1 i=3 [/home2/niroj_p]starting serv_nm retrieving attributes of object serv_nm ... done setting up the server resources retrieving node object mars6 ... done creating file system path /var/opt/encina/local/subsys/encina/css6/server/serv_nm ... exists retrieving encina server group name ... done retrieving encina administration organization ... done starting serv_nm retrieving attributes of object serv_nm ... done setting up the server resources retrieving node object mars6 ... done creating file system path /var/opt/encina/local/subsys/encina/css6/server/serv_nm... exists retrieving encina server group name ... done retrieving encina administration organization ... done + kill -9 0 # Kill is working nice ===================== After this I have to enter any key to come out from the process. That I want to avoid.. Thank u friends... ![]() |
|
||||
|
Are you sure you really must use kill -9? It can be dangerous. Try with kill -2 first.
The proper (or at least customary, and easiest) way to get the process ID is with x=$! right after starting the background job. I don't understand the for loop, do you start two separate processes and sleep a maximum of one second between them? I'm not certain about the need to press a key after the process is killed; are you sure it's not the second round of the loop? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|