r_a_j_e_s_h
asked on
4 line prog which gives core dump.
i saw this qn in 1 of the qn papers.
4 line program which gives core dump.
4 line program which gives core dump.
ASKER
that is my question.
i want the program which gives core dump.
i want the program which gives core dump.
#include <string.h>
int main ()
{
char * p = NULL;
strcpy (p, "core dump\n");
}
You can make up tons of them ...
int main ()
{
char * p = NULL;
p[7]=' ';
}
...
....
int main ()
{
char * p = NULL;
strcpy (p, "core dump\n");
}
You can make up tons of them ...
int main ()
{
char * p = NULL;
p[7]=' ';
}
...
....
2 more programs to dump core.
1st one is with arithmetic exception.
2nd one is with segmentation fault.
/* Program 1 */
#include <stdio.h>
int main(int argc, char **argv)
{
int i = 1/0;
}
/* Program 1 Ends */
/* Program 2 */
#include <stdio.h>
main()
{
int *i = NULL;
*i = 0;
}
/* Program 2 Ends */
-ssnkumar
1st one is with arithmetic exception.
2nd one is with segmentation fault.
/* Program 1 */
#include <stdio.h>
int main(int argc, char **argv)
{
int i = 1/0;
}
/* Program 1 Ends */
/* Program 2 */
#include <stdio.h>
main()
{
int *i = NULL;
*i = 0;
}
/* Program 2 Ends */
-ssnkumar
Hello rajesh,
int *p;
main()
{
printf("%d",*p);
}
try the above example,
int *p;
main()
{
printf("%d",*p);
}
try the above example,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi r_a_j_e_s_h,
To get the full picture of all actions which lead to a core dump, just check the system's default behaviour (man signal / man -s 5 signal). Those marked as core are by default creating a core dump when raised. Not all POSIX signals are created by all platforms (Linux x86 doesn't throw SIGBUS, for example).
Once you know which signals lead to a core dump, it's quite easy to create one. You can simply raise a fake signal:
#include <signal.h>
int main(){
raise(SIGSEGV);
return 0;
}
Cheers!
Stefan
To get the full picture of all actions which lead to a core dump, just check the system's default behaviour (man signal / man -s 5 signal). Those marked as core are by default creating a core dump when raised. Not all POSIX signals are created by all platforms (Linux x86 doesn't throw SIGBUS, for example).
Once you know which signals lead to a core dump, it's quite easy to create one. You can simply raise a fake signal:
#include <signal.h>
int main(){
raise(SIGSEGV);
return 0;
}
Cheers!
Stefan
-ssnkumar