Trapping Interrupt From 'ulimit'


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Trapping Interrupt From 'ulimit'
# 1  
Old 04-06-2005
Trapping Interrupt From 'ulimit'

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
# 2  
Old 04-06-2005
SIGXCPU is the right signal. You can bet that ksh gets it. But ksh does not make all signals available to the script for direct manipulation. trap 0 is invoked whenever a script exits for any reason.

Make this two scripts, a monitor script and the real script. The real script will touch a flag file when it starts. If it finishes normally it removes the flag file. The monitor script will run the real script. Then it sends mail if the flag file exists.

Or rewrite the script in C. Then you can access every signal.
# 3  
Old 04-19-2005
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:

==================================================

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 Smilie
# 4  
Old 04-19-2005
Apologies... i happened to send the post without giving the output for the failure of trap.

It goes like this.

==================================================
#!/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]

==================================================
# 5  
Old 04-19-2005
Your analysis is very interesting. The problem is that you are thinking of the shell script as a single unit but to the kernel it is a collection of processes. In your first case you used nothing except ksh built-in commands. In this case, ksh itself exceeded the one second limit. But in the second case ksh did not use a full second. It was "find" that ran too long. The find process got a signal and was killed. After the death of the find command, ksh continued to run. But it ran to completion without consuming a full second of cpu time.
# 6  
Old 04-22-2005
OK what you say makes sense and it does work the way you have mentioned. But I really don't understand why would a function like 'trap' would be built if it ends up working the way it does.

I don't understand why the signal interrupt sent to the child process is not passed back to the parent process. (As 'trap' forms a part of the parent process and not the child process). If the interrupt was sent to the parent then it would have got trapped and everything would have been good.
Tried getting this information but couldn't get to the crux of the matter.
These signal commands I gather can do a lot of manipulation. But i am lacking in that area.

The solution as i have found out to trapping the signal interrrupt and going in the overlib function is to use 'timex -opf' option. This adds a return code from the "command" which was being used, which inturn got the interrupt, and hence the STAT column in 'timex -opf' gets set to a non zero value to indicate that it was an interrupt and an error.
You may ask why not use the return code from the command directly. But the obvious answer being, will not know whether the error was because of interrupt or beacuse of some valid error. Also if timex -op needs to be used inherently then signal interrupt sent to the command terminates the command and timex -op by itself being a independent child process executes sucessfully with 0 return code.

basically.. think of the following command getting a signal interrupt coz of 'ulimit -t 1' and how will one be able to capture the same to go in overlib.

timex -op find / -name "*haha*" 1> tempout.$$ 2> temperr.$$


This does help me solve my problem, but me not happy with not being able to used 'trap' directly. Oh well.. lets see.

Anyways thanx Perderabo.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to interrupt running application?

Hello i have problem passing ctrl+C into shell script this script will run application and return value but never ends and stay running. i tried trap and not working at all the command should look like this : sarm pcsp -s CHG_M_P1 i want something to stop this command after... (9 Replies)
Discussion started by: mogabr
9 Replies

2. What is on Your Mind?

Alarm interrupt and multithreading

Hi Friends any know how became a friend in this Android Programming Language (0 Replies)
Discussion started by: ljarun
0 Replies

3. UNIX for Advanced & Expert Users

Is there any shell command to show which interrupt handler handle which interrupt number?

Hi, all: Is there any shell command to show which interrupt handler handle which interrupt number in the system? li,kunlun (5 Replies)
Discussion started by: liklstar
5 Replies

4. UNIX for Advanced & Expert Users

Interrupt storm detected on "irq 20" throttling interrupt source

I receive the following warning messages on a very new machine which has FreeBSD 8.1 x64 installed on it: Interrupt storm detected on "irq 20" throttling interrupt source It is unclear what this means and what its origins are (motherboard? CPU? RAM?). I can start the desktop and the message is... (4 Replies)
Discussion started by: figaro
4 Replies

5. UNIX for Advanced & Expert Users

hunting down for software interrupt causes

Hi, i have an rhel box with around 20 %soft every 2 seconds. The box is idle. How do i start hunting down what's causing this? i believe /proc/interrupts is hardware related, procinfo is basically the same. where else can i look? thanks, Marc (5 Replies)
Discussion started by: marcpascual
5 Replies

6. Shell Programming and Scripting

Interrupt handling in k shell

Hi All, Is interrupt handling possible in k shell? Say if the user press CTRL-C or CTRl-D,I want to perform a particular action before terminating? Thnaks! (2 Replies)
Discussion started by: prasperl
2 Replies

7. Shell Programming and Scripting

Sending an interrupt in a script?

Is it possible to sent a ^C interrupt via the command line? For example if I want to tail a log for 10 minutes at a time, kill the tail and then start it again is there a way to go about that? I would imagine there would be some way to do it by finding and killing the PID, but I'm curious if... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

8. UNIX for Dummies Questions & Answers

timer interrupt

hello all since a process running in kernel mode cannnot be preempted by any other process what would be the status of Timer interrupt that occurs when the time quantum of a process is elapsed? thanks (2 Replies)
Discussion started by: compbug
2 Replies

9. UNIX for Advanced & Expert Users

Interrupt level 14 woes

Hi there, My first post here. Currently, i have been experiencing this error quite frequently on a ultra5 com. Things i have done is changing a new hdd and mem modules but i still encounter this error. Some messages from the var/adm WARNING: uncorrectable error from pci0 (upa mid 0) during... (0 Replies)
Discussion started by: kerwen
0 Replies

10. UNIX for Dummies Questions & Answers

erase and interrupt keys

This is on our Ultra 5/10 Sparc with Solaris 9. I need to store the following (stty) keys in the .profile and /etc/profile files as shown here. erase "Back Space Key" Interrupt "Ctrl + C" I need the exact syntax/procudure as I have to set these two keys whenever I login to the terminal... (1 Reply)
Discussion started by: chrs0302
1 Replies
Login or Register to Ask a Question

Featured Tech Videos