Hi I started with the bug( https://bugs.winehq.org/show_bug.cgi?id=39640 ). As of what I understood, I am writing it below. Kindly correct me wherever I go wrong. To implement ProcessPage_OnEndProcessTree() correctly we need to kill all its children and grandchildren also. So for that purpose, we need to iterate through all the active processes and check if their parent process is same as the process we wish to terminate. If yes, we kill them, if no, we continue our iteration. Now, for implementing this, can we use 'ps' or 'top' command. An example code:
char string[30] = "ps -o pid --ppid "; char ppid[7]; sprintf(ppid , "%d" , getpid() ) ; strcat ( string , ppid ) ; system ( string ) ;
ps -o pid --ppid <parent_Id> will give us the pid of all the child_processes whose parent has a PID. And now, get the parentProcess's PID by getpid(). Next, convert the integer into string and concatenate the result with string to get the final command which is then executed by system(string).
Kindly tell me if I am anywhere near the right solution and also guide me how to proceed.
Thanks :) Regards -- Akarsha Sehwag
Hi,
While I'm not an expert in this part of wine, I want to point out that while it's definitely one way to do it, it's not the best way. You're relying on System() here which in turn relies on the output of the ps command. There's many potential issues here:
1. You have to make sure the output of the command you're executing will be the same across all systems. This could be an issue for cross-platform compatibility. 2. System() spawns extra processes which introduces overhead, which could be a problem on systems with limited resources. 3. 'ps' itself could have been removed, or modified maliciously, or only executable as root, probably anything could happen.
IMO, as much as possible, you should rely on using the existing API's provided within
François had posted an attachment in the comments containing a related implementation which you could refer. Hope it helps! You can find it here https://bugs.winehq.org/show_bug.cgi?id=39644#c1
Feel free to ask any further questions you have. Make sure to CC wine-devel in your replies so other devs can see and help if need be.
Cheers, Aaryaman
On Sun, Mar 26, 2017 at 9:55 PM, Akarsha Sehwag akarsha15010@iiitd.ac.in wrote:
Hi I started with the bug( https://bugs.winehq.org/show_bug.cgi?id=39640 ). As of what I understood, I am writing it below. Kindly correct me wherever I go wrong. To implement ProcessPage_OnEndProcessTree() correctly we need to kill all its children and grandchildren also. So for that purpose, we need to iterate through all the active processes and check if their parent process is same as the process we wish to terminate. If yes, we kill them, if no, we continue our iteration. Now, for implementing this, can we use 'ps' or 'top' command. An example code:
char string[30] = "ps -o pid --ppid "; char ppid[7]; sprintf(ppid , "%d" , getpid() ) ; strcat ( string , ppid ) ; system ( string ) ;
ps -o pid --ppid <parent_Id> will give us the pid of all the child_processes whose parent has a PID. And now, get the parentProcess's PID by getpid(). Next, convert the integer into string and concatenate the result with string to get the final command which is then executed by system(string).
Kindly tell me if I am anywhere near the right solution and also guide me how to proceed.
Thanks :) Regards -- Akarsha Sehwag
On 27 March 2017 at 12:48, Aaryaman Vasishta jem456.vasishta@gmail.com wrote:
François had posted an attachment in the comments containing a related implementation which you could refer. Hope it helps! You can find it here https://bugs.winehq.org/show_bug.cgi?id=39644#c1
There's an issue with the implementation in that attachment though. Process32First() and Process32Next() will change the current position in the snapshot, so using them in a recursive function like that will potentially skip over some processes.