I am confronted to a very weird problem.
When running my very simple one file program via NetBeans, I have the following error:
RUN FINISHED; Segmentation fault; core dumped; real time: 150ms; user: 0ms; system: 0ms
My run command is simple ./Name-Of-The-File.
When I use a terminal and cd to the folder containing the program and run the same command, I get the following output:
Hullo
PLatform Number is : 1
Hullo
(Note that the Hullos were added to pinpoint where the segfault happened, as my very first line in main() prints Hullo.)
Here is the code of the program:
/*
* File: main.cpp
* Author: sysgen
*
* Created on June 4, 2015, 7:08 PM
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <utility>
#include <CL/cl.hpp>
const std::string hw("Hello World \n");
/*
*
*/
//OpenCL Error checking function
inline void checkErr(cl_int err, const char *name){
if (err != CL_SUCCESS){
std::cerr << "FATAL OPENCL ERROR: " << name << "( " << err << ") " << std::endl;
exit(EXIT_FAILURE);
}
}
int main(void) {
//Creating an OpenCL context
std::cout << "Hullo" << std::endl;
cl_int err;
std::vector< cl::Platform > platformList; //We make a vector which will contain the platforms
cl::Platform::get(&platformList);
checkErr(platformList.size() !=0 ? CL_SUCCESS : -1, "cl::Platform::get");
std::cerr << "PLatform Number is : " << platformList.size() << std::endl;
std::string platformVendor;
platformList[0].getInfo((cl_platform_info)CL_PLATFORM_VENDOR, &platformVendor);
std::cout << "Hullo" << std::endl;
return 0;
}
This error also manifests in codeblocks. There is more details produced by gdb:
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /home/sysgen/NetBeansProjects/OpenCL SVOGL/
Adding source dir: /home/sysgen/NetBeansProjects/OpenCL SVOGL/
Adding file: /home/sysgen/NetBeansProjects/OpenCL SVOGL/bin/Debug/OpenCL SVOGL
Changing directory to: "/home/sysgen/NetBeansProjects/OpenCL SVOGL/."
Set variable: LD_LIBRARY_PATH=.:/opt/AMDAPPSDK-3.0-0-Beta/lib/x86_64/:/usr/lib32
Starting debugger: /usr/bin/gdb -nx -fullname -quiet -args "/home/sysgen/NetBeansProjects/OpenCL SVOGL/bin/Debug/OpenCL SVOGL"
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Reading symbols from /home/sysgen/NetBeansProjects/OpenCL SVOGL/bin/Debug/OpenCL SVOGL...(no debugging symbols found)...done.
Debugger name and version: GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9
Program received signal SIGSEGV, Segmentation fault.
In ?? () ()
177 dlerror.c: No such file or directory.
#1 0x00007ffff70dd6fd in init () at dlerror.c:177
Related
I am attempting to profile a program that requires data loaded from a sqlite database. Running the program normally works as expected, but when I use callgrind the opened database is empty (no tables; a user_version that is set in the database comes back as 0). The database file is found at the correct path, and appears to be correctly opened, but there is nothing in it.
Test program (sqlite_test.cpp):
#include <sqlite3.h>
#include <iostream>
#include <sys/stat.h>
bool dbExists() {
struct stat s;
if (stat("testDB", &s) != 0) {
return false;
}
else {
return true;
}
}
int main()
{
if (dbExists())
std::cout << "db exists\n";
sqlite3 *db;
int open = sqlite3_open_v2("testDB", &db, SQLITE_OPEN_READWRITE, NULL);
if (open == SQLITE_OK) {
std::cout << "db opened\n";
}
else {
std::cout << "Failed to open DB; code: " << open << "\n";
}
sqlite3_stmt *stmt;
sqlite3_prepare_v2(db, "PRAGMA user_version;", -1, &stmt, NULL);
int dbVersion = 0;
int res = sqlite3_step(stmt);
if (res == SQLITE_ROW) {
dbVersion = sqlite3_column_int(stmt, 0);
}
else {
std::cout << "DB version not set: " << res << " " << sqlite3_errstr(res) << "\n";
}
std::cout << "Database version: " << dbVersion << std::endl;
sqlite3_close(db);
}
I created a database ("testDB") that has "pragma user_version = 5;", and is located in the same folder as the executable. The executable is built using
g++ sqlite_test.cpp -lsqlite3 -o sqlite_test
Output:
# ./sqlite_test
db exists
db opened
Database version: 5
# valgrind --tool=callgrind ./sqlite_test
==1184== Callgrind, a call-graph generating cache profiler
==1184== Copyright (C) 2002-2015, and GNU GPL'd, by Josef Weidendorfer et al.
==1184== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==1184== Command: ./sqlite_test
==1184==
==1184== For interactive control, run 'callgrind_control -h'.
db exists
db opened
Database version: 0
==1184==
==1184== Events : Ir
==1184== Collected : 2787290
==1184==
==1184== I refs: 2,787,290
One other thing I have noticed is that it seems to work fine when running with valgrind (memcheck). It is only with callgrind that the problem shows up. This is true for both valgrind 3.12 and 3.14.
Update:
Obviously I should have mentioned what I am running this on, because it appears to be the source of the problem.
My problem is on a system running Yocto 2.2.2 (Morty) on a single core ARM processor. There is no problem if I run the same thing on a different system (which is a virtual machine) running Ubuntu 18.04.
I am not sure which difference between those systems is causing the problem.
I am running a beaglebone and want to write a program to sample the ADC. I am trying to use the blacklib (http://blacklib.yigityuce.com/index.html) from here. I cloned the git:
https://github.com/yigityuce/BlackLib
and tried to compile the example with
g++ exampleAndTiming.cpp -std=c++11
This however gives me a ton of errors like these:
In file included from exampleAndTiming.cpp:33:0:
exampleAndTiming/exampleAndTiming_GPIO.h: In function 'void exampleAndTiming_GPIO()':
exampleAndTiming/exampleAndTiming_GPIO.h:97:12: error: 'sleep' was not declared in this scope
sleep(1);
^
In file included from exampleAndTiming.cpp:34:0:
exampleAndTiming/exampleAndTiming_ADC.h: In function 'void exampleAndTiming_ADC()':
exampleAndTiming/exampleAndTiming_ADC.h:67:16: error: 'usleep' was not declared in this scope
usleep(1000);
^
so I include unistd.h (in exampleAndTiming.cpp), but then I get errors like these:
/tmp/ccbgiXE9.o: In function `exampleAndTiming_GPIO()':
exampleAndTiming.cpp:(.text+0x50): undefined reference to `Timing::startMeasure(std::string)'
exampleAndTiming.cpp:(.text+0x80): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0xbc): undefined reference to `Timing::endMeasure(std::string)'
exampleAndTiming.cpp:(.text+0xec): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0x104): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0x11c): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0x158): undefined reference to `Timing::startMeasure(std::string)'
I've been looking at some library examples and compiling it, but I cannot make sense of it all. I've compiled plenty of c++ and c programs before, but I can't get this one to work. So any help will be appreciated.
COMPLETE GUIDE how to compile BLACKLIB directly on BEAGLEBONE BLACK (rev C) running ANGSTROM:
Programs:
Putty - to communicate with BBB from Windows (using SSH with USB cable)
WinSCP - to manage (upload, create, delete) files directly on BBB
Code::Blocks - to write C++ programs
optionally
Termite 2.9 - to send and receive UART transmission from UART<->USB converter (actually Putty could be used to do that as well)
1) get the BlackLib from official site
2) unzip the library and copy following files into separate folder :
BlackADC.cpp, BlackADC.h, BlackCore.cpp, BlackCore.h, BlackDef.h, BlackErr.h, BlackGPIO.cpp, BlackGPIO.h, BlackI2C.cpp, BlackI2C.h, BlackLib.h, BlackPWM.cpp, BlackPWM.h, BlackSPI.cpp, BlackSPI.h, BlackUART.cpp, BlackUART.h
3) open following files in Code::Blocks BlackUART.cpp, BlackSPI.cpp, BlackI2C.cpp and add
#include <unistd.h>
right after #include "BlackUART.h", the "unistd.h" includes all the functions like sleep(), open(), close(), ... that otherwise seems missing
4) create your own program main.cpp, you may use the following code for testing UART1 and UART2:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sstream>
#include <string>
#include <iostream>
#include "BlackLib.h"
int main(){
std::string writeToUart1;
std::string writeToUart2;
std::string readFromUart1;
std::string readFromUart2;
int counter;
std::ostringstream os1;
std::ostringstream os2;
BlackLib::BlackUART Uart1(BlackLib::UART1,
BlackLib::Baud9600,
BlackLib::ParityEven,
BlackLib::StopOne,
BlackLib::Char8 );
// Pins on BeagleBone Black REV C
// UART1_RX -> GPIO_15 (P9.24)
// UART1_RX -> GPIO_14 (P9.26)
BlackLib::BlackUART Uart2(BlackLib::UART2,
BlackLib::Baud9600,
BlackLib::ParityEven,
BlackLib::StopOne,
BlackLib::Char8 );
// Pins on BeagleBone Black REV C
// UART2_RX -> GPIO_2 (P9.22)
// UART2_RX -> GPIO_3 (P9.21)
std::cout << "Program UART start" << std::endl << std::flush;
Uart1.open( BlackLib::ReadWrite | BlackLib::NonBlock );
Uart2.open( BlackLib::ReadWrite | BlackLib::NonBlock );
counter = 0;
while (true){
os1.str("");
os1.clear();
os1 << "Uart1 to TX: " << counter << "\n";
writeToUart1 = os1.str();
Uart1 << writeToUart1;
readFromUart1 = "";
Uart1 >> readFromUart1;
if (readFromUart1.compare("") != 0){
std::cout << "Uart1 from RX: " << readFromUart1 << "\n" << std::flush;
}
Uart1.flush( BlackLib::bothDirection );
counter++;
sleep(2);
os2.str("");
os2.clear();
os2 << "Uart2 to TX: " << counter << "\n";
writeToUart2 = os2.str();
Uart2 << writeToUart2;
readFromUart2 = "";
Uart2 >> readFromUart2;
if (readFromUart2.compare("") != 0){
std::cout << "Uart2 from RX: " << readFromUart2 << "\n" << std::flush;
}
Uart2.flush( BlackLib::bothDirection );
counter++;
sleep(2);
}
return 1;
}
5) save the main.cpp to the same folder as the BlackLib files
6) using WinSCP, create directory on the BBB (e.g. /home/uart) and copy all the BlackLib files and main.cpp into this folder
7) open Putty and navigate to the folder by :
cd /home/uart
8) compile the files by using :
gcc *.cpp -o main -std=c++11
9) run the program :
./main
10) connect the wires to UART<->USB converter and BBB. The ouput from BBB should look like :
Uart2 to TX: 1 OR Uart1 to TX: 0
Uart2 to TX: 3 OR Uart1 to TX: 2
depending on connection of wires
It seems I managed to fix it myself, some nooblike behaviour not including all the cpp files, but even more, I also needed to add #include to BlackCore.h to avoid tons of undefined function errors.
final command:
g++ exampleAndTiming.cpp exampleAndTiming/Timing.cpp BlackADC.cpp BlackCore.cpp BlackGPIO.cpp BlackI2C.cpp BlackPWM.cpp BlackSPI.cpp BlackUART.cpp -std=c++11
I'd probably need to make a makefile to compile the library seperately, time to do some more digging and learning.
I am the creator of BlackLib, Yiğit YÜCE. You found your answer by yourself. The makefile which you mentioned on your comment will be published shortly.
My Linux C++ application crashing while writing strings into ostream object.
My original application tries to create a very bigg string output and write all string output into a stream. while writing the string into ostream object, the application crashed. At first the the crash was happened in both windows and Linux.
Now the issue fixed in Windows environment (details below). but In Linux it is crashing.
Following is the sample c++ program, that will generate the same scenario.
#include <iostream>
#include <strstream>
#include <memory>
using namespace std;
bool fillScreen(std::ostream&);
int main ()
{
auto_ptr<ostrstream> screen(new ostrstream);
bool succ = false;
try
{
succ = fillScreen(*screen);
}catch(std::exception &ex)
{
std::cerr << ex.what() << std::endl;
}
if(succ)
{
std::cout << "SCREEN Content is : " << screen->str() << std::endl;
}
else
{
std::cout << "NOTHING ON SCREEN Object " << std::endl;
}
}
bool fillScreen(ostream &scr)
{
unsigned long idx = 0;
scr.exceptions(std::ios::badbit);// throws exception in windows but not in Linux.
while (idx++ < 999999999)
{
scr << "BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH_" << " : " ;
scr << "BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_";
scr << "BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_"<< std::endl;
/*if(!(idx %100000))
{
std::cout << "Reached iteration: " << idx << std::endl;
}*/
}
return true;
}
I have added following statement, in my program
screen.exceptions(std::ios::badbit);
With this statement, my programs not crashing in windows.
While running on windows, the stream throws badbit exception and my application handle the exception and made a clean exit.
Output as follows,
Windows output: (run using cygwin)
$ ./overflow.exe
bad allocation
NOTHING ON SCREEN Object
Clean exit.
Linux Output:
[Mybuild#devlnx01 streamError]$ ./a.out
Segmentation fault (core dumped)
[Mybuild#devlnx01 streamError]$
Crashed - Not a clean exit. Even with exceptions set
screen.exceptions(std::ios::badbit);
Following is the stack trace taken using Linux gdb, (using core dump file)
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0 std::strstreambuf::overflow (this=0x17f8018, c=72) at ../../.././libstdc++-v3/src/strstream.cc:174
174 ../../.././libstdc++-v3/src/strstream.cc: No such file or directory.
in ../../.././libstdc++-v3/src/strstream.cc
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.107.el6.x86_64
(gdb) where
#0 std::strstreambuf::overflow (this=0x17f8018, c=72) at ../../.././libstdc++-v3/src/strstream.cc:174
#1 0x00007eff6f4e7565 in std::basic_streambuf<char, std::char_traits<char> >::xsputn (this=0x17f8018, __s=<value optimized out>, __n=72)
at /export/disk1/build/GCC4.5.3/gcc-4.5.3/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/streambuf.tcc:97
#2 0x00007eff6f4ddb85 in sputn (__out=..., __s=0x401038 "BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH_", __n=72)
at /export/disk1/build/GCC4.5.3/gcc-4.5.3/x86_64-unknown-linux-gnu/libstdc++-v3/include/streambuf:429
#3 __ostream_write<char, std::char_traits<char> > (__out=...,
__s=0x401038 "BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH_", __n=72)
at /export/disk1/build/GCC4.5.3/gcc-4.5.3/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h:48
#4 std::__ostream_insert<char, std::char_traits<char> > (__out=...,
__s=0x401038 "BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH_", __n=72)
at /export/disk1/build/GCC4.5.3/gcc-4.5.3/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/ostream_insert.h:99
#5 0x00007eff6f4dde0f in std::operator<< <std::char_traits<char> > (__out=...,
__s=0x401038 "BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH_")
at /export/disk1/build/GCC4.5.3/gcc-4.5.3/x86_64-unknown-linux-gnu/libstdc++-v3/include/ostream:513
#6 0x0000000000400d82 in fillScreen (scr=...) at overflow.cxx:35
#7 0x0000000000400c31 in main () at overflow.cxx:14
version and compiler details.
Windows 2008 (64bit) - VS2008
rhel62(64bit) gcc version 4.4.7
Compilation arguments.
$g++ overflow.cxx -g3 -m64 -O0 -ggdb
In Windows it is exiting properly, But in Linux this is crashing with segmentation fault error.
All i am looking for is my application should do clean exit. i do not want it to exit with segmentation fault error.
I am not sure how to handle this in Linux, Can any one guide me on this.
This seems to be an issue with the standard library shipping with your copy of gcc on linux.
Update your compiler (4.8.1 is the current version of gcc, as of 30. September 2013) and you'll get the expected behaviour as you can see in this demo.
Side note: auto_ptr shouldn't be used anymore. Use unique_ptr or shared_ptr. In this case, neither is necessary, drop the new.
I get the error
lldb: /home/hannes/.llvm/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2271: uint64_t ::RecordLayoutBuilder::updateExternalFieldOffset(const clang::FieldDecl *, uint64_t): Assertion `ExternalFieldOffsets.find(Field) != ExternalFieldOffsets.end() && "Field does not have an external offset"' failed.
Aborted (core dumped)
when I try to print a vector<string>. Does anyone know why this happens, and how to fix it? The equivalent works just fine in gdb (there are a number of reason why I'd rather use / have to use lldb over gdb).
I'm running Ubuntu 12.10 with llvm, clang and lldb trunk.
The program, build instructions and lldb command sequence:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using std::for_each;
using std::begin;
using std::end;
int main() {
std::vector<std::string> vec{"Hello","World","!"};
for_each(begin(vec),end(vec),[](const std::string& s) {
std::cout << s << " ";
});
std::cout << std::endl;
return 0;
}
clang++ -g -c -std=c++11 main.cpp
clang++ -std=c++11 main.o -o test
lldb test
Current executable set to 'test' (x86_64).
(lldb) break -n main
invalid command 'breakpoint -n'
(lldb) breat set -n main
error: 'breat' is not a valid command.
(lldb) break set -n main
Breakpoint 1: where = test`main + 26 at main.cpp:5, address = 0x0000000000400aea
(lldb) run
Process 24489 launched: '/home/hannes/Documents/Programming/CXX/test/test' (x86_64)
Process 24489 stopped
* thread #1: tid = 0x5fa9, 0x0000000000400aea test`main + 26 at main.cpp:5, stop reason = breakpoint 1.1
frame #0: 0x0000000000400aea test`main + 26 at main.cpp:5
2 #include <string>
3
4 int main() {
-> 5 std::vector<std::string> vec{"Hello","World","!"};
6 return 0;
7 }
n
Process 24489 stopped
* thread #1: tid = 0x5fa9, 0x0000000000400c72 test`main + 418 at main.cpp:6, stop reason = step over
frame #0: 0x0000000000400c72 test`main + 418 at main.cpp:6
3
4 int main() {
5 std::vector<std::string> vec{"Hello","World","!"};
-> 6 return 0;
7 }
frame variable
lldb: /home/hannes/.llvm/llvm/tools/clang/lib/AST/RecordLayoutBuilder.cpp:2271: uint64_t <anonymous namespace>::RecordLayoutBuilder::updateExternalFieldOffset(const clang::FieldDecl *, uint64_t): Assertion `ExternalFieldOffsets.find(Field) != ExternalFieldOffsets.end() && "Field does not have an external offset"' failed.
Aborted (core dumped)
Log output with debug level 10:
Logging from function (<frame object at 0x3172f20>, '/usr/lib/python2.7/dist-packages/lldb/formatters/cpp/gnu_libstdcpp.py', 141, '__init__', ['\t\tlogger = lldb.formatters.Logger.Logger()\n'], 0)
Providing synthetic children for a map named vec
Logging from function (<frame object at 0x3170d10>, '/usr/lib/python2.7/dist-packages/lldb/formatters/cpp/gnu_libstdcpp.py', 214, 'update', ['\t\tlogger = lldb.formatters.Logger.Logger()\n'], 0)
Does the same thing happen if you say frame variable --raw?
This command is meant to dump your vector disabling data formatters. In the specific case you will get (assuming no crashes) the in-memory layout of the vector instead of the printout of the strings you stored there.
I am mostly trying to figure out if the data formatters are or not a part in this issue.
My program (C++ on Solaris 10) writes output via wcout to its terminal when it is started from a shell. But when I execute it from within Sun Studio or the file manager is does not have a terminal and the ouput appears in the Sun Studio output window or nowhere at all.
I would like it to open its own terminal window in any of the three cases and attach wcout to this terminal window. I want this to be done be the program itself with C++ system calls not by the way how the program is executed from some shell or script. Because then execution in the Studio IDE and double-click in the file manager would still have the same effect.
Being a Windows programmer that seems quite natural to me but I could not find out how this is done in my Unix books nor in the web. Am I requesting the wrong thing, is it really so hard to do or am I missing something?
The following is close to what you want. It still has a few bugs:
The xterm cannot be normally closed (it closes when the program terminates, though). I have no idea why this is so.
Before the intended output, a number is output. Again, I have no idea why.
I don't seem to be able to redirect input.
Maybe someone else know how to fix those bugs (and any others I might not have noticed).
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
#include <sstream>
int main()
{
int pt = posix_openpt(O_RDWR);
if (pt == -1)
{
std::cerr << "Could not open pseudo terminal.\n";
return EXIT_FAILURE;
}
char* ptname = ptsname(pt);
if (!ptname)
{
std::cerr << "Could not get pseudo terminal device name.\n";
close(pt);
return EXIT_FAILURE;
}
if (unlockpt(pt) == -1)
{
std::cerr << "Could not get pseudo terminal device name.\n";
close(pt);
return EXIT_FAILURE;
}
std::ostringstream oss;
oss << "xterm -S" << (strrchr(ptname, '/')+1) << "/" << pt << " &";
system(oss.str().c_str());
int xterm_fd = open(ptname,O_RDWR);
char c;
do read(xterm_fd, &c, 1); while (c!='\n');
if (dup2(pt, 1) <0)
{
std::cerr << "Could not redirect standard output.\n";
close(pt);
return EXIT_FAILURE;
}
if (dup2(pt, 2) <0)
{
std::cerr << "Could not redirect standard error output.\n";
close(pt);
return EXIT_FAILURE;
}
std::cout << "This should appear on the xterm." << std::endl;
std::cerr << "So should this.\n";
std::cin.ignore(1);
close(pt);
return EXIT_SUCCESS;
}
You want to output to a file (redirect, using a logging API or close stdout/reopen it as a file). And then tail it with tail -f in a terminal of your choice.
This has added benefit of saving your log output for review even if the terminal crashes/is killed.
When you invoke your program, instead of running: myprog 1 2 3 a b c, run xterm -e myprog 1 2 3 a b c.
I would recommnend to create a shell script that runs the terminal to which you pass your program to execute, then you should call that script instead of your program from the file manager.
Your script.sh:
#!/bin/sh
xterm -e /path_to_your_program/your_program
Using mknod to create pipe in /tmp every linux have /tmp and everyone always allowed to use it
system("mknod /tmp/printing_pipe pipe");
system("qterminal -e tail -f /tmp/printing_pipe");
write to the /tmp/printing_pipe to use it