LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2018, 12:54 PM   #1
ravisiswaliya
LQ Newbie
 
Registered: Feb 2018
Location: India
Posts: 1

Rep: Reputation: Disabled
Question 6862 Segmentation fault (core dumped)


/bin/bash: line 1: 6862 Segmentation fault (core dumped) "/home/ravisiswaliya/Desktop/practice/u"
Got this error when try to run this program

#include</usr/include/python3.4/Python.h>
#include <stdlib.h>
#include <string.h>


int main(int argc, char *argv[])
{
Py_Initialize();
//PySys_SetPath("/home/ravisiswaliya/Desktop/practice");
PyObject *pval, *pName, *pModule, *pFunc, *pDict;
const char *cString = "Cyberpersons";
//PyBytes_FromString is used at the place of PySring_FromString
pval = PyBytes_FromString(cString);
pName = PyBytes_FromString(argv[11]);
pModule = PyImport_Import(pName);

//construct function arguments
PyObject *pythonArgument, *pValue;
pythonArgument = PyTuple_New(11);
pValue = PyBytes_FromString(argv[13]);

if(pValue == NULL){
return 1;
}
PyTuple_SetItem(pythonArgument, 0, pValue);

//calling a python function
pFunc = PyObject_GetAttrString(pModule,argv[12]);
pValue = PyObject_CallObject(pFunc, pythonArgument);
printf("Hello C\n");

Py_Finalize();
}
 
Old 02-04-2018, 01:46 PM   #2
Mill J
Senior Member
 
Registered: Feb 2017
Location: @127.0.0.1
Distribution: Mint, Void, MX, Haiku, PMOS, Plasma Mobile, and many others
Posts: 1,258
Blog Entries: 2

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
Please provide more info such as what distribution/version are you using, what tools you're using, and most importantly what you're trying to accomplish with this code.

To me it looks like a cross between c and python? please explain.
 
Old 02-04-2018, 02:42 PM   #3
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Code:
pValue = PyBytes_FromString(argv[13]);
Holy cow! I'd like to see the command line used to launch this program.
 
Old 02-04-2018, 03:35 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Welcome to LQ!

Please place your code snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls.

As pointed out by others, you have not asked a complete question, or any question at all. Posting code snippets and an error message does not help others to understand what you are trying to accomplish or why it may not be working.

Please review the Site FAQ for guidance in asking complete and well formed questions.

Remember that the more oyu help others here to understand your problem, the better responses you will receive.
 
Old 02-05-2018, 06:52 AM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
If this is your code and it appears to be in C, you can compile it using debug flags and use GDB to analyze the core file, as well as use GDB to run it, set breakpoints, and examine the variables just before, or just after it crashes.

You've done a typical thing here which is to post "here's my code, I got an error", we're not here to review your code, we are volunteers, but happy to help. Meanwhile it would be helpful to know things like whether or not you're compiling using GCC, and how you're running this program, because that error report makes no sense. It should not talk about /bin/bash if you are running a C program, instead it should talk about the resultant binary program from compiling that C program. Right now it appears that this error you've posted has nothing to do with C code and instead something to do with a script. For analyzing core files, you can refer to a blog entry I've made, however the core would have to be resulting from your compiled C code.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getting segmentation fault(core dumped) in ns-2 jaiswal.raaj Linux - Wireless Networking 2 12-26-2014 10:06 PM
Segmentation fault (core dumped) mohammad taqy bayat Linux - Newbie 3 08-25-2014 02:10 AM
Segmentation fault (core dumped) mezyana Linux - Newbie 1 05-18-2014 03:52 PM
Segmentation fault (core dumped) sirjase Programming 8 12-18-2013 03:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration