-
-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add thisPid() and Pid.getThis() #3448
Conversation
|
|
|
How about a |
|
Ah, I guess |
| /** Returns the $(D Pid) of the current process. | ||
|
|
||
| Usage of this function is preferred over $(D thisProcessID) as $(D Pid) is more | ||
| typesafe that int. For instance $(LREF kill) requires a $(D Pid) as argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/that/than/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"," after "for instance"
|
LGTM |
|
I think we need either |
|
If we remove |
|
The allocation per call for (essentially) an immutable seems wasteful. But the whole idea here seems wasteful. The only places Pid is used is in Do we need to add a whole new API call for this? You can do |
|
@schveiguy, I agree that the allocation in Can the result of If not, shouldn't the result of @schveiguy, I thought the policy of Phobos was to, when possible, wrap untyped interfaces (UNIX-style |
Yes, if the process is forked. |
|
@schveiguy, if |
|
@schveiguy The fault seems to be with Pid being a class. Any chance to undo that w/o deprecating the whole thing? |
|
@DmitryOlshansky changing it to a |
|
@nordlow typesafety I guess. Effectively it seems to be an opaque type for whatever is the platform specific process handle/integer |
|
The point of making it a class, I think, is to avoid leaking the handle (specifically for Windows). I'm curious if we couldn't generate the Handle each time it's needed, and then close the handle within the same function ( Another option is to create an overload for ping @kyllingstad |
Yes, but if you do this: auto pid = thisPid;
fork();you have the same problem. The trick would be somehow to detect a change in the current process and update the singleton. I admit, I don't like this idea at all :) |
Well, this is funny. It was, in fact, you who convinced me to make To everyone else: The reason I don't think there is a compelling use case for |
|
In other words, I don't think this pull request should be merged. |
As I typed it, I knew deep down I was going to be at fault here :) The thing about Pid construction right now is that it only happens when creating a process. So we don't have to worry about the performance of using the heap -- process creation is heavy anyway. But accessing a property which is 'this process' shifts the overhead. Are there any other use cases? If not, let's just close this. |
I'll bite - there is INVALID_HANDLE on windows, what's the problem with invalidation? |
If Pid is a struct, then one can close the handle by terminating the process in one instance, but it remains unchanged in another instance. Then you are operating on essentially free'd memory (which may have been allocated again) with the second instance: auto pid2 = pid1;
pid1.wait();
pid2.wait(); // what does this do?Really, you could do |
Got it. This looks like overkill. |
|
I'm using it to suspend a process from within the process itself. |
Again, I don't see how this warrants a dedicated Phobos function. You're trying to do a POSIX-specific thing here, so what's wrong with using POSIX functions? You can even avoid pulling in |
|
Closing, since there seems to be consensus for doing so. |
This adds a typesafer version of
thisProcessIDnamedthisProcessPid.See discussion at http://forum.dlang.org/post/pziiwlhoyyolgvvljgcg@forum.dlang.org.