[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

RE: [LI] Catching SIGSEGV



Hi Vimal,
	Please note that YOU ARE HANDLING THE SIGSEGV signal ON YOUR OWN so
it's your responsibility to handle the exit also, otherwise it will keep on
printing <Seg. Fault>. The action ,kernel takes when segmentation fault
occurs, is :
--> dump the core image 
--> exit the program
(off course there is one case in which we get a message
Segmentation fault occurred
without any core dump)
Since you are taking the responsibility of kernel on your shoulder so please
take care of this.
Put exit(0); in the signal handler function and you'll get <Seg. Fault> only
once.
HTH
Ajit 
----------------------------------------------------------------------------
-------------------------
Best way to learn Linux is to put comments in the source code
___________________________________________________

> -----Original Message-----
> From:	Vimal Mathew [SMTP:vml@xxxxxxxxxxxxx]
> Sent:	Monday, January 17, 2000 2:56 PM
> To:	linux-india@xxxxxxxxxxxxxxxxxxxxx
> Subject:	[LI] Catching SIGSEGV
> 
> Hi,
> 	A program I wrote used a signal handler for SIGSEGV. I originally
> compiled it without any extra flags. When any instruction in the program
> seg. faulted, it would get a large no. of Segmentation fault signals (I
> checked with strace and ltrace), and the program would exit. The same
> program, if compiled with optimization flags (-O2) would work as expected.
> I tried compiling with both gcc and egcs under RH5.2 and egcs in RH6.1.
> The program fragment is given below
> 
> jmp_buf env;
> 
> void seg_catch()
> {
> 	printf("<Seg. fault>\n");
> 	longjmp(env, 1);
> }
> main()
> {
> 	......	/* Setup handlers etc. */
> 	......
> 	if (setjmp(env) == 0) {
> 		....
> 		<seg. faulting statements>
> 	} else {
> 		....
> 	}
> }
> 
> --------------------------------------------------------------------
> The Linux India Mailing List Archives are now available.  Please search
> the archive at http://lists.linux-india.org/ before posting your question
> to avoid repetition and save bandwidth.
--------------------------------------------------------------------
The Linux India Mailing List Archives are now available.  Please search
the archive at http://lists.linux-india.org/ before posting your question
to avoid repetition and save bandwidth.