Sign in to follow this  

checking if a process exists

This topic is 3659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a pid, and I'm trying to figure out if it corresponds to any process that is currently running. (the pid gets appended to some temp files I write out. On app startup I'm checking if any of my temp files correspond to crashed runs of my app) The only ways I've found of doing this are calling EnumProcesses() on Windows or checking if /proc/myPid exists on unix platforms (I think, don't have a non-windows machine to try). I'm hoping there is a more cross-platform way to do this?

Share this post


Link to post
Share on other sites
No, there is no cross-platform way to do this.

Also your approach is flawed in that pids get reused. Just because pid 37 wrote to your log file some time in the past and pid 37 exists now, doesn't mean they're the same program. Even if "some time in the past" was just a few seconds (or less) ago.

To do what you want reliably you would have to communicate with each running instance of your app and ask it "dude, is this your file?" - however there's no cross-platform way to do that either. You might be able to play games with log files that are locked, again though, compatibility is in no way guaranteed.

Share this post


Link to post
Share on other sites
I know its not bulletproof, but periodically cleaning up the temp files on startup seems better than nothing.

I figure if the files are prefixed with "companyname.appname.version.pid.blah blah..." and stored in the user's temp directory, it should be good enough to tell the file came from my app, and with the pid, enough to know that it corresponds to a current execution of the app.

Share this post


Link to post
Share on other sites

This topic is 3659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this