-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Implemented getpid(p::Process)
.
#24064
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,6 +331,17 @@ end | |
pipe_reader(p::Process) = p.out | ||
pipe_writer(p::Process) = p.in | ||
|
||
""" | ||
getpid(p::Process) -> Int32 | ||
|
||
Get the process ID of a running process. Returns `-1` if the | ||
process is not running. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about alternatives when the process is not running, like throwing, or returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning Also, as @vtjnash mentioned before, we can take guidance from nodejs where child pid is accessible via a property which does not throw. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran an experiment with node, and it looks like they cache the pid: > const { spawn } = require('child_process');
> x = spawn('sleep', ['1']);
> x.exitCode
0
> x._handle
null
> x.pid
45660 I still don't think this is a good idea for the reasons I mentioned above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is essentially the same question as #18145. But upon reflection, I think an error would be better here. In some places, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. I'll make the change. Just to make sure: caching the pid is off the table. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
function Libc.getpid(p::Process) | ||
p.handle != C_NULL || error("process not running") | ||
ccall(:jl_uv_process_pid, Cint, (Ptr{Cvoid},), p.handle) | ||
end | ||
|
||
struct ProcessChain <: AbstractPipe | ||
processes::Vector{Process} | ||
in::Redirectable | ||
|
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.
Why not return
Int
?EDIT: oh I see,
getpid()
returnsInt32
already, but still...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.
Right. I just copied that line from the
Base.getpid()
doc. The actual type isCint
, but I think that is the same asInt32
on all the supported platforms.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.
Yes, this was the right choice (matching
getpid()
)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.
What about changing that to
Int
for both methods in another PR? for example, one method ofkill
(withClusterManager
) accepts a pid asInt
.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.
@rfourquet - isn't that a different ID? I thought
kill(::ClusterManager, ..)
takes the worker id, not the OS process id.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.
It seems you are right.