HPE GreenLake Administration
- Community Home
 - >
 - Servers and Operating Systems
 - >
 - Operating Systems
 - >
 - Operating System - HP-UX
 - >
 - atexit, getting the exit code
 
Operating System - HP-UX
        1840158
        Members
    
    
        3104
        Online
    
    
        110162
        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
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
 
02-13-2004 02:37 AM
02-13-2004 02:37 AM
			
				
					
						
							atexit, getting the exit code
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Is there a way for an atexit handler to get
the exit code that was in the exit call ?
like exit(5), in my atexit registered
function, can I determine it was 5 ?
I am using the atexit to register an exit
handler for a C program, using the aCC compiler, hpux 11.0
		
		
	
	
	
the exit code that was in the exit call ?
like exit(5), in my atexit registered
function, can I determine it was 5 ?
I am using the atexit to register an exit
handler for a C program, using the aCC compiler, hpux 11.0
		3 REPLIES 3
	
	            
            
		
		
			
            
                - Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
02-13-2004 02:40 AM
02-13-2004 02:40 AM
			
				
					
						
							Re: atexit, getting the exit code
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Hi James,
echo $?
will give you exit code.
HTH,
Jeff
		
		
	
	
	
echo $?
will give you exit code.
HTH,
Jeff
	PERSEVERANCE  --  Remember, whatever does not kill you only makes you stronger!
			
			
				
			
			
			
			
			
			
		- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
02-13-2004 02:52 AM
02-13-2004 02:52 AM
			
				
					
						
							Re: atexit, getting the exit code
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						Because the handlers pushed by atexit expect no arguments there is no direct, portable method to accomplish this. However, you should be able to
create a wrapper function for exit(), e.g myexit() that first takes the argument and assigns it to a global variable which your handlers could then access.
e.g.
int Exit_Status = 1;
/* sample silly function to feed atexit() */
void myexithandler()
{
(void) fprintf(stderr,"Exit Status = %d\n",Exit_Status);
(void) fflush(stderr);
return;
} /* myexithandler */
Now instead of using exit() in your code, use myexit();
void myexit(int status)
{
Exit_Status = status;
exit(status);
/* NOTREACHED */
return;
} /* myexit */
					
				
			
			
				
		
		
	
	
	
create a wrapper function for exit(), e.g myexit() that first takes the argument and assigns it to a global variable which your handlers could then access.
e.g.
int Exit_Status = 1;
/* sample silly function to feed atexit() */
void myexithandler()
{
(void) fprintf(stderr,"Exit Status = %d\n",Exit_Status);
(void) fflush(stderr);
return;
} /* myexithandler */
Now instead of using exit() in your code, use myexit();
void myexit(int status)
{
Exit_Status = status;
exit(status);
/* NOTREACHED */
return;
} /* myexit */
	If it ain't broke, I can fix that.
			
			
				
			
			
			
			
			
			
		- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
02-15-2004 04:52 PM
02-15-2004 04:52 PM
			
				
					
						
							Re: atexit, getting the exit code
						
					
					
				
			
		
	
			
	
	
	
	
	
			
				
					
					
						(there seems to be no nice API for this)
defining something with a name other than exit will not let you catch exit's that are not called form your code.
you can define your own 'void exit(int status) which will override exit() of libc. put your atexit handler code in this exit() routine and at the end a call to '_exit(status)'. the difference between calling exit() and _exit() is in the exit() man page.
if you run into problems because of other (crt0/dld.sl) atexit handlers not being called, you may need to implement atexit() as well ...
					
				
			
			
				
	 
--
ranga
[i work for hpe]
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
defining something with a name other than exit will not let you catch exit's that are not called form your code.
you can define your own 'void exit(int status) which will override exit() of libc. put your atexit handler code in this exit() routine and at the end a call to '_exit(status)'. the difference between calling exit() and _exit() is in the exit() man page.
if you run into problems because of other (crt0/dld.sl) atexit handlers not being called, you may need to implement atexit() as well ...
--
ranga

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