Home > Net >  Is there a way to find out which process started another process in the rust programming language
Is there a way to find out which process started another process in the rust programming language

Time:09-09

I am making an app for my cousin that blocks apps at certain times of the day. I am trying to setup an easy gui based approach to block apps that is intuitive and easy to use. I get all of the apps from the start menu folders, then get their corresponding executables, and then put them in a grid list so that from the apps user interface, the user can add app and remove applications easily.

Unfortunately, some apps aren’t quite so easy… If an app has an updater app for it, most often, the shortcut in the start menu will refer the the updater app, then the updater will check for updates, apply updates, then run the program. But with my system, it would automatically pick up the updater program as the blocked app, not the actual app. That’s why I want to be able to see what program started another program. Then I can see if a program was started by the updater, then I will know that it is part of the app too, and I should block that app aswell.

I am pretty sure that this is possible, but I don’t know how to do this in rust. This forum says it should be possible: https://superuser.com/questions/541210/find-what-process-started-another-process.

CodePudding user response:

The sysinfo crate should be helpful here - if you know the name of the app you want to block, you can use the list of all processes to find the process you want to block and find its parent process. You may have to repeat this traversal a few times to find the original launching process, but be wary about what process are blocking - you may find your way back to an OS/root process which you definitely don't want to block.

  • Related