I want to know the interrupt passed to a process through 'ulimit'
I am running a process which gets killed when the 'ulimit -t' reaches.
But after killing the process I want to start another process which would
send a message or do some clean up or anything at all.
To do the same I am using 'trap' and a function call, which does, rest of the
activity (mailing, cleanup, etc). But the problem is using the interrupt signal for trap.
I have tried using all from 1 to 38 which are mentioned in the "/usr/include/sys/iso/signal_iso.h" file.
But those signals are not what 'ulimit' sends to kill a running process on the system.
On the other hand what i observed was if "0" is used with trap, then the ulimit interrupt
is trapped and I am able to run the over head function in trap. But using 0 does not make
sense. And i have also not found any reference for the same mentioned anywhere.
In addition to the same. I tried using 'truss' to give me information as to which interrupt
is sent to my running process and truss shows that it is "/2: Received signal #30, SIGXCPU [default]"
But if i use 'trap' with 30 .. it still does not help.
Any ideas as to what kind of interrrupt does 'ulimit' send to a process and how can one trap the same.
To give u a sample of the code I am using. Please refer to the following example.
#!/bin/ksh
trapme(){
echo "stoppid me"
touch haha.$$
}
callmain(){
trap 'trapme' 30
truss find ./ -name "*signal*" | grep "_iso" | grep ".h" 1> tempout.$$ 2> temperr1.$$
}
callmain
I had posted this on some other forums as well. Would like to know what people out here think. I had recieved some replies for this and based on which I have done the following.
Okie I have gone forward and done some more research on the same.
Your idea of using C shell is very true and it works. But I guess I won't be able to use the same.
As long as the signal getting passed to korn shell is concerned here is my analysis.
If i use the following script,
==================================================
#!/bin/ksh
ulimit -t 1
trap 'echo "CPU time limit exceeded"; exit 2' XCPU
num=1
while true
do
echo $num >> haha
num=`expr $num + 1`
done
Output:
asakpal[/export/home/asakpal] ksh r.sh
CPU time limit exceeded
asakpal[/export/home/asakpal] echo $?
2
asakpal[/export/home/asakpal]
==================================================
then the trap works fine and it does what it's supposed to do.
Basically this argument refutes the fact that
"But ksh does not make all signals available to the script for direct manipulation."
But on the other hand if i use this following script.
==================================================
#!/bin/ksh
ulimit -t 1
trap 'echo "CPU time limit exceeded"; exit 2' XCPU
find / -name "*haha*" 2> /dev/null
Output:
asakpal[/export/home/asakpal] ksh f.sh
f.sh[17]: 13404 Cpu Limit Exceeded
asakpal[/export/home/asakpal] echo $?
158
asakpal[/export/home/asakpal]
==================================================
then I get a core dumped error. But I still do not get a my echo message.
What baffles me is that for one type of execution trap works while for other it doesn't. Any more ideas