I have a WPF application that starts a new process using Process.Start(ProcessStartInfo info)
.
How do I get the group process ID of the process so that I can send a Ctrl+C signal using GenerateConsoleCtrlEvent
? https://msdn.microsoft.com/en-us/library/windows/desktop/ms683155%28v=vs.85%29.aspx
However, I can't seem to find the group process ID of the console window in the new process that is created. It has a session ID for the cur windows user and a process ID.
edit: I finally got my program to work but I still never found a true answer to my real question.
I was able to send ctrl c to a process by using GenerateConsoleCtrlEvent to broadcast to all processes in a console.
However, I was not able to figure out how to get the process group of a process that is running. You can of course save the process group if you create a new process (it should be the ID of the process that called createprocess with the creation flag for create new process group). However, I cannot find anything related to actually grabbing this ID if you are not making a new group yourself and just wish to know the group that a process belongs to. Surely this information is stored somewhere and can be retrieved!
I can get the parent ID in windows NT versions using this function:
Fetching parent process Id from child process
However, this does not guarantee the same process group. I am starting to conclude that windows does not have get process group id from process id function.
Linux has a simple getpgrp function that does want I am looking for. I don't understand why windows has a process group if I can't get the value of it
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…