func main() {
pid := 1567 // This is the process id of one of the chrome tabs on my machine. I got it from Task Manager.
const da = syscall.STANDARD_RIGHTS_READ | syscall.PROCESS_QUERY_INFORMATION | syscall.SYNCHRONIZE
_, err := syscall.OpenProcess(da, false, uint32(pid))
fmt.Printf("Error: %v\n", err)
}--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/p-H5ODtTXIw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
The following line seems to wait infinitely on my machine (Windows 8.1 x64). Im not quite sure if this is intended for a check like "is this process still running", because you wont get an answer if it is.
processState, err := process.Wait()
Also you dont handle all errors (no feedback for the user), like access denied for func FindProcess(pid int) (*Process, error) or the following:
func (p *Process) Wait() (*ProcessState, error)
Wait waits for the Process to exit, and then returns a ProcessState describing its status and an error, if any. Wait releases any resources associated with the Process. On most operating systems, the Process must be a child of the current process or an error will be returned.
I don't know if you know, but you can use Job Objects to monitor / manage group of processes on Windows. See https://github.com/golang/benchmarks/blob/master/driver/driver_windows.go#L65 for an example
The following line seems to wait infinitely on my machine (Windows 8.1 x64). Im not quite sure if this is intended for a check like "is this process still running", because you wont get an answer if it is.
On most operating systems, the Process must be a child of the current process or an error will be returned.
Maybe you could use a socket + keep-alive pings. Simple to implement and plattform-/language-independent.
To close a job object handle, use the CloseHandle function. The job is destroyed when its last handle has been closed and all associated processes have exited. However, if the job has the JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE flag specified, closing the last job object handle terminates all associated processes and then destroys the job object itself.
--