If run daemonize on 04_video_dec_trt sample ends abnormally in buildTrtContext()

If run daemonize on 04_video_dec_trt sample ends abnormally in buildTrtContext().

I ran the typical daemoize code but the 04_video_dec_trt sample ends abnormally with the log below.

/usr/src/jetson_multimedia_api/samples/04_video_dec_trt$ sudo ./video_dec_trt 2 /usr/src/jetson_multimedia_api/data/Video/sample_outdoor_car_1080p_10fps.h264 /usr/src/jetson_multimedia_api/data/Video/sample_outdoor_car_1080p_10fps.h264 H264 --trt-deployfile /usr/src/jetson_multimedia_api/data/Model/resnet10/resnet10.prototxt --trt-modelfile /usr/src/jetson_multimedia_api/data/Model/resnet10/resnet10.caffemodel --trt-mode 0
set deployfile: /usr/src/jetson_multimedia_api/data/Model/resnet10/resnet10.prototxt
set modefile: /usr/src/jetson_multimedia_api/data/Model/resnet10/resnet10.caffemodel
Try to call the buildTrtContext().
Net has batch_size, channel, net_height, net_width:2 3 368 640
Using cached TRT model

how can I daemonize the 04_video_dec_trt sample?

video_dec_trt_main.cpp (33.5 KB)

Hi
For running 04_video_dec_trt on JP4.5(r32.5), certain files are missing. Please try with the files in
I confirmed that mmapi has been updated to the 32.5 release - #5 by DaneLLL

We installed JP4.5 (r32.5).
Building 04_video_dec_trt was successful.
04_video_dec_trt was successfully executed and the log is as follows.

=============================================

jetson73@jetson73-desktop:/usr/src/jetson_multimedia_api/samples/04_video_dec_trt$ sudo ./video_dec_trt 1 …/…/data/Video/sample_outdoor_car_1080p_10fps.h264 H264 --trt-onnxmodel …/…/data/Model/resnet10/resnet10_dynamic_batch.onnx --trt-mode 0
set onnx modefile: …/…/data/Model/resnet10/resnet10_dynamic_batch.onnx
Using cached TRT model
Opening in BLOCKING MODE
Opening in BLOCKING MODE
NvMMLiteOpen : Block : BlockType = 261
NVMEDIA: Reading vendor.tegra.display-size : status: 6
NvMMLiteBlockCreate : Block : BlockType = 261
Starting decoder capture loop thread
Video Resolution: 1920x1080
Resolution change successful
Input file read complete
Time elapsed:21 ms per frame in past 100 frames
Time elapsed:20 ms per frame in past 100 frames
Time elapsed:20 ms per frame in past 100 frames
Time elapsed:20 ms per frame in past 100 frames
Time elapsed:20 ms per frame in past 100 frames
Exiting decoder capture loop thread
Inference Performance(ms per batch):22 Wait from decode takes(ms per batch):0
App run was successful
jetson73@jetson73-desktop:/usr/src/jetson_multimedia_api/samples/04_video_dec_trt$

=============================================

I just added a very simple daemoize code to the 04_video_dec_trt example.

=============================================

static int daemonize(void)
{
pid_t pid;
int rc;

// daemon initialzation
if ( (pid = fork()) < 0 )
	return -1;
else if (pid != 0)
	exit(0);		// parent goes bye-bye
	
// child continues
setsid();			// become session leader
rc = chdir("/");			// change working directory
umask(0);			// clear our file mode creation mask
return rc;

}

=============================================

Call daemonize() in the main() function of video_dec_trt_main.cpp.
Building 04_video_dec_trt was successful.

=============================================

if (parseCsvArgs(ctx, &trt_ctx_wrap, argc, argv))
{
    cerr << "Error parsing commandline arguments." << endl;
    return -1;
}

daemonize();
setDefaults(ctx, &trt_ctx_wrap);

=============================================

When 04_video_dec_trt is executed, the following message appears, and it ends immediately.

=============================================
jetson73@jetson73-desktop:/usr/src/jetson_multimedia_api/samples/04_video_dec_trt$ sudo ./video_dec_trt 1 …/…/data/Video/sample_outdoor_car_1080p_10fps.h264 H264 --trt-onnxmodel …/…/data/Model/resnet10/resnet10_dynamic_batch.onnx --trt-mode 0
set onnx modefile: …/…/data/Model/resnet10/resnet10_dynamic_batch.onnx
jetson73@jetson73-desktop:/usr/src/jetson_multimedia_api/samples/04_video_dec_trt$

=============================================
Attach the entire file with daemoinze() added to the 04_video_dec_trt example in JP4.5(r32.5).04_video_dec_trt.tar (8.2 MB)
How do I run the 04_video_dec_trt example as a daemon?

Hi,
This case may not be verified. Could you share the reason to run it in child process? Would like to know the valid usecase.

And we have DeepStream SDK. You may try it for running deep learning inference.

We developed AI-Box based on Jetson, which can be controlled remotely through Web GUI without a local person.
Also, we made our own H/W such as carrier board and case.

Currently, the inference process is almost implemented.
We want the inference process to run as a background process automatically with Jetson boot.

daemonize() is the most popular way to create background processes.
We request that you modify the 04_video_dec_trt sample to make daemonize() work, or tell us how to create a background process in another way.
Unfortunately, the DeepStream SDK is not an alternative, since the product development is almost complete.

I would like to ask if there is any progress on how to create a background process.
I think this is a very important issue for both us and jetson AI.
I look forward to your answer.

Hi,
The issue is under investigation. Will check if we can support this case.

Are there any progress toward the successful execution of background processes?

Hi,
We did some investigation but so fat not have conclusion yet. It looks to be an issue in trt_inference.cpp. Seems like certain variables are global and when the parent process exits, the child process is dead, too. The issue is not seen in another similar samples:

/opt/nvidia/deepstream/deepstream-5.1/sources/apps/sample_apps/deepstream-test1/
/usr/src/tensorrt/samples/sampleOnnxMNIST/

Since you have mentioned DeepStream SDK is not considered in your usecase. Are you able to refer to sampleOnnxMNIST for further development?

We got the answer to the above question through a different route.
DeepStream and TensorRT were not fully or partially IPC implemented and this is the cause of the problem.
We had no choice but to remove the existing Daemonize source and use the service file.