1 /** 2 Processes 3 4 Copyright: 5 Copyright © 2023-2025, Kitsunebi Games 6 Copyright © 2023-2025, Inochi2D Project 7 8 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) 9 Authors: Luna Nielsen 10 */ 11 module nulib.threading.process; 12 import nulib.threading.internal.process; 13 import numem; 14 15 /** 16 A process. 17 */ 18 class Process : NuObject { 19 private: 20 @nogc: 21 NativeProcess process_; 22 23 public: 24 25 /** 26 The current running process. 27 */ 28 static @property Process thisProcess() @safe { 29 if (auto proc = NativeProcess.thisProcess) 30 return nogc_new!Process(proc); 31 32 return null; 33 } 34 35 /** 36 The ID of the process. 37 */ 38 @property uint pid() @safe => process_.pid; 39 40 // Destructor 41 ~this() { 42 nogc_delete(process_); 43 } 44 45 /** 46 Constructs a new high level process from its 47 native equiavlent. 48 49 Params: 50 process = The native process handle. 51 */ 52 this(NativeProcess process) { 53 this.process_ = process; 54 } 55 56 /** 57 Kills the given process. 58 59 Returns: 60 $(D true) if the operation succeeded, 61 $(D false) otherwise. 62 */ 63 bool kill() @safe { 64 return process_.kill(); 65 } 66 } 67 68 @("thisProcess") 69 unittest { 70 assert(Process.thisProcess); 71 assert(Process.thisProcess.pid != 0); 72 }