@@ -1823,6 +1823,43 @@ fn os_wait(vm: &VirtualMachine) -> PyResult<(libc::pid_t, i32)> {
1823
1823
os_waitpid ( -1 , 0 , vm)
1824
1824
}
1825
1825
1826
+ fn os_kill ( pid : i32 , sig : isize , vm : & VirtualMachine ) -> PyResult < ( ) > {
1827
+ #[ cfg( unix) ]
1828
+ {
1829
+ let ret = unsafe { libc:: kill ( pid, sig as i32 ) } ;
1830
+ if ret == -1 {
1831
+ Err ( errno_err ( vm) )
1832
+ } else {
1833
+ Ok ( ( ) )
1834
+ }
1835
+ }
1836
+ #[ cfg( windows) ]
1837
+ {
1838
+ use winapi:: um:: { handleapi, processthreadsapi, wincon, winnt} ;
1839
+ let sig = sig as u32 ;
1840
+ let pid = pid as u32 ;
1841
+
1842
+ if sig == wincon:: CTRL_C_EVENT || sig == wincon:: CTRL_BREAK_EVENT {
1843
+ let ret = unsafe { wincon:: GenerateConsoleCtrlEvent ( sig, pid) } ;
1844
+ let res = if ret == 0 { Err ( errno_err ( vm) ) } else { Ok ( ( ) ) } ;
1845
+ return res;
1846
+ }
1847
+
1848
+ let h = unsafe { processthreadsapi:: OpenProcess ( winnt:: PROCESS_ALL_ACCESS , 0 , pid) } ;
1849
+ if h. is_null ( ) {
1850
+ return Err ( errno_err ( vm) ) ;
1851
+ }
1852
+ let ret = unsafe { processthreadsapi:: TerminateProcess ( h, sig) } ;
1853
+ let res = if ret == 0 { Err ( errno_err ( vm) ) } else { Ok ( ( ) ) } ;
1854
+ unsafe { handleapi:: CloseHandle ( h) } ;
1855
+ res
1856
+ }
1857
+ #[ cfg( not( any( unix, windows) ) ) ]
1858
+ {
1859
+ unimplemented ! ( )
1860
+ }
1861
+ }
1862
+
1826
1863
pub fn make_module ( vm : & VirtualMachine ) -> PyObjectRef {
1827
1864
let ctx = & vm. ctx ;
1828
1865
@@ -1932,6 +1969,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
1932
1969
"lseek" => ctx. new_function( os_lseek) ,
1933
1970
"set_inheritable" => ctx. new_function( os_set_inheritable) ,
1934
1971
"link" => ctx. new_function( os_link) ,
1972
+ "kill" => ctx. new_function( os_kill) ,
1935
1973
1936
1974
"O_RDONLY" => ctx. new_int( libc:: O_RDONLY ) ,
1937
1975
"O_WRONLY" => ctx. new_int( libc:: O_WRONLY ) ,
0 commit comments