MCPcopy Create free account
hub / github.com/appleboy/CodeGPT / createKillOnCloseJob

Function createKillOnCloseJob

util/api_key_helper_windows.go:20–41  ·  view source on GitHub ↗

createKillOnCloseJob creates a Windows Job Object with KILL_ON_JOB_CLOSE flag. When the job handle is closed, all processes in the job will be terminated.

()

Source from the content-addressed store, hash-verified

18// createKillOnCloseJob creates a Windows Job Object with KILL_ON_JOB_CLOSE flag.
19// When the job handle is closed, all processes in the job will be terminated.
20func createKillOnCloseJob() (windows.Handle, error) {
21 job, err := windows.CreateJobObject(nil, nil)
22 if err != nil {
23 return 0, err
24 }
25
26 var info windows.JOBOBJECT_EXTENDED_LIMIT_INFORMATION
27 // Enable KILL_ON_JOB_CLOSE flag
28 info.BasicLimitInformation.LimitFlags = windows.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
29
30 _, err = windows.SetInformationJobObject(
31 job,
32 windows.JobObjectExtendedLimitInformation,
33 uintptr(unsafe.Pointer(&info)),
34 uint32(unsafe.Sizeof(info)),
35 )
36 if err != nil {
37 _ = windows.CloseHandle(job)
38 return 0, err
39 }
40 return job, nil
41}
42
43// assignProcessToJob assigns a process to a Job Object.
44// Returns the process handle which should be closed by the caller.

Calls

no outgoing calls