I was able to do this by creating the process group when starting the process and used CTRL_BREAK_EVENT when terminating the process.
You can see the sample code in below thread:
https://stackoverflow.com/a/79755815/5979669