HPE GreenLake Administration
- Community Home
 - >
 - Servers and Operating Systems
 - >
 - Operating Systems
 - >
 - Operating System - HP-UX
 - >
 - SIGALRM question
 
Operating System - HP-UX
        1840122
        Members
    
    
        2475
        Online
    
    
        110161
        Solutions
    
Forums
        Categories
Company
Local Language
                
                  
                  back
                
        
                
        
                
        
                
        
        
        
                
        
                
        
        
        
                
        
              
              Forums
Discussions
Forums
- Data Protection and Retention
 - Entry Storage Systems
 - Legacy
 - Midrange and Enterprise Storage
 - Storage Networking
 - HPE Nimble Storage
 
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
                
                  
                  back
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
            
                
            
                
            
                
            
                
            
            
                
            
                
            
            
                
            
                
              
            Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
 - Appliance Servers
 - Alpha Servers
 - BackOffice Products
 - Internet Products
 - HPE 9000 and HPE e3000 Servers
 - Networking
 - Netservers
 - Secure OS Software for Linux
 - Server Management (Insight Manager 7)
 - Windows Server 2003
 - Operating System - Tru64 Unix
 - ProLiant Deployment and Provisioning
 - Linux-Based Community / Regional
 - Microsoft System Center Integration
 
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
        Information
        Community
Resources
Community Language
        Language
        Forums
Blogs
	
		
			
            
                
            Go to solution
        
            
		
		
			
            	
	
		
        
		
	
	
		Topic Options
			
				
					
	
			
		
	- Subscribe to RSS Feed
 - Mark Topic as New
 - Mark Topic as Read
 - Float this Topic for Current User
 - Bookmark
 - Subscribe
 - Printer Friendly Page
 
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
06-09-2003 09:32 AM
06-09-2003 09:32 AM
			
				
					
					
						I have a perl script that uses $SIG{ALRM} to exit the program:
$timeout = 10;
$SIG{INT} = 'wrapup';
$SIG{TERM} = 'wrapup';
$SIG{ALRM} = 'timeout';
alarm $timeout;
print ROOTLOG "Before while loop - timeout length=$timeout\n";
$i = 1;
while ($i < 20) {
sleep 2;
print ROOTLOG "Inside while loop: call $i\n";
&flush(ROOTLOG);
$i++;
}
However, the sigalrm isn't breaking out of the code. The loop should stop after its 5th iteration, but it continues to 20. I have ruled out any problem with Perl since it works fine on other HP-UX boxes with the same version. Is there anything that could be blocking SIGALRM? SIG{INT} and SIG{TERM} work fine.
Thanks
	
			
				
		
			
			
			
			
			
			
		
		
		
	
	
	
$timeout = 10;
$SIG{INT} = 'wrapup';
$SIG{TERM} = 'wrapup';
$SIG{ALRM} = 'timeout';
alarm $timeout;
print ROOTLOG "Before while loop - timeout length=$timeout\n";
$i = 1;
while ($i < 20) {
sleep 2;
print ROOTLOG "Inside while loop: call $i\n";
&flush(ROOTLOG);
$i++;
}
However, the sigalrm isn't breaking out of the code. The loop should stop after its 5th iteration, but it continues to 20. I have ruled out any problem with Perl since it works fine on other HP-UX boxes with the same version. Is there anything that could be blocking SIGALRM? SIG{INT} and SIG{TERM} work fine.
Thanks
Solved! Go to Solution.
		3 REPLIES 3
	
	            
            
		
		
			
            
                - Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
06-09-2003 10:26 AM
06-09-2003 10:26 AM
Solution
			
				
					
					
						Basically because you are not quite playing by the rules. It appears that signal handling is a bit different in this particular Perl implementation but in any event you should never rely upon a SIGALRM handler to work when you are using a loop which includes sleep. Sleep uses SIGALRM as well.
I suggest that you test my theory by replacing your sleep with an artifical delay loop where the sleep 2 currently is.
e.g.
$j = 1;
while ($j <= 500000)
{
$x = ((1.5 * $j) + 3.568) / ($i + 4.67);
++$j;
}
(This is just a complex enough statement to require a bit of processing. You may need to play with the limits of the loop to approximate your 2 second sleep.)
I think that you will now find that the SIG{ALRM} now works as expected.
By the way, the better approach is to put the alarm($timeout), the call that does something, and the alarm(0) - to cancel the alarm inside an eval.
					
				
			
			
				
		
		
	
	
	
I suggest that you test my theory by replacing your sleep with an artifical delay loop where the sleep 2 currently is.
e.g.
$j = 1;
while ($j <= 500000)
{
$x = ((1.5 * $j) + 3.568) / ($i + 4.67);
++$j;
}
(This is just a complex enough statement to require a bit of processing. You may need to play with the limits of the loop to approximate your 2 second sleep.)
I think that you will now find that the SIG{ALRM} now works as expected.
By the way, the better approach is to put the alarm($timeout), the call that does something, and the alarm(0) - to cancel the alarm inside an eval.
	If it ain't broke, I can fix that.
			
			
				
			
			
			
			
			
			
		- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
06-10-2003 04:00 AM
06-10-2003 04:00 AM
			
				
					
						
							Re: SIGALRM question
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Ok, that worked.  But here's something to cook your noodle.  The script as it was originally written with the sleep command works on every other HP-UX box running the same OS.  These are slower machines (C240 vs C3700).  Any idea?
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
06-10-2003 07:12 AM
06-10-2003 07:12 AM
			
				
					
						
							Re: SIGALRM question
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						It's almost certainly not the OS but the specific Perl port. My best guess is that that the alarm signal handler does not reset the previous signal handler but instead sets SIGALRM to be ignored but you would really have to look at the Perl source itself to know.
					
				
			
			
				
		
		
	
	
	
	If it ain't broke, I can fix that.
			
			
				
			
			
			
			
			
			
		The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
		
	
	
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP