Crash in cudaMemcpy after fork and wait for a child process

System: Jetson AGX Xavier, example ubuntu image from NVIDIA, Kernel 4.9.140, JetPack 4.4 (L4T R32.4.3).
Following minimalized code example reproduces it:

#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

using namespace std;

// Minimalized example out of QProcess (Qt 5.14.2)
void forker()
pid_t pid = fork();
if (pid == 0)
cout << “PID child process: " << getpid() << endl;
char* argv[] = {”/bin/ls", “-l”, “/home/ “, NULL};
execv(”/bin/ls”, argv);
else if (pid > 0)
cout << "PID parent process: " << getpid() << endl;
cerr << “Error!”;

static void initValues(unsigned char result[10])
for (int i = 0; i < 10; i++) {
result[i] = 3;

int main(int, const char * const [])
static unsigned char data1[10];


unsigned char(*gpu_ptr_1)[10UL];
cudaMalloc(&gpu_ptr_1, 10UL);
cudaMemcpy(*gpu_ptr_1, data1, 10UL, cudaMemcpyHostToDevice);

cout << " after first malloc " << endl;


cout << " after forker " << endl;

static unsigned char data2[10];

unsigned char(*gpu_ptr_2)[10UL];
cudaMalloc(&gpu_ptr_2, 10UL);
cudaMemcpy(*gpu_ptr_2, data2, 10UL, cudaMemcpyHostToDevice);

cout << " after last malloc " << endl;


Let us check your source first.
Will update more information with you later.



Not sure if we miss something.
We slightly modify your source, and can run it on Xavier + JetPack4.5 without crashing. (1.1 KB)

$ nvcc -o test
$ ./test

after first malloc
PID parent process: 9946
PID child process: 9948
/bin/ls: cannot access '/home/ ': No such file or directory
after forker
after last malloc


1 Like

Hi AastaLLL,

It’s fantastic to hear, that you reach 'after last malloc' without having a segmentation fault before! Was it fixed in JetPack4.4.1 or 4.5 or is it maybe a kernel issue? On which kernel version did you test? I’m working in a yocto project on Xavier and not very agile in swapping JetPack versions. I would be glad to know, where the problem was solved.

Thank you very much!


We test it on JetPack 4.5.
You can give it a try.


Hi AastaLLL

I tested it on JetPack 4.5 (not 4.5.1) but sometimes it still crashed and sometimes not!?!? It seems to run better but even not stable. (I run the code in a loop and it failed after about 50 times, after sudo apt upgrade after about 5 cycles or earlier)

Any idea?

Thanks for your help!