LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   6862 Segmentation fault (core dumped) (https://www.linuxquestions.org/questions/programming-9/6862-segmentation-fault-core-dumped-4175623084/)

ravisiswaliya 02-04-2018 12:54 PM

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();
}

Mill J 02-04-2018 01:46 PM

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.

norobro 02-04-2018 02:42 PM

Code:

pValue = PyBytes_FromString(argv[13]);
Holy cow! I'd like to see the command line used to launch this program.

astrogeek 02-04-2018 03:35 PM

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.

rtmistler 02-05-2018 06:52 AM

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.


All times are GMT -5. The time now is 05:00 PM.