?
Solved

4 line prog which gives core dump.

Posted on 2005-03-28
7
Medium Priority
?
275 Views
Last Modified: 2010-04-15
i saw this qn in 1 of the qn papers.

4 line program which gives core dump.
0
Comment
Question by:r_a_j_e_s_h
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 8

Expert Comment

by:ssnkumar
ID: 13642393
Where is the program?

-ssnkumar
0
 
LVL 3

Author Comment

by:r_a_j_e_s_h
ID: 13642538
that is my question.
i want the program which gives core dump.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 13642679
#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]=' ';
}
...
....
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:ssnkumar
ID: 13642955
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
0
 
LVL 9

Expert Comment

by:Suhas .
ID: 13649555
Hello rajesh,

int *p;
main()
{
     printf("%d",*p);
}

try the above example,
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 500 total points
ID: 13653894
Most of the above examples are more than 4 lines.  How about:

int main()
{
      *(int *)0 = 0;
}
0
 
LVL 12

Expert Comment

by:stefan73
ID: 13654393
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question