Author eryksun
Recipients eryksun, jpe, steve.dower, tim.golden, zach.ware
Date 2015-12-10.07:20:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The signal module switched to using an enum for signal values: 

    >>> print(*map(repr, sorted(signal.Signals)), sep='\n')
    <Signals.CTRL_C_EVENT: 0>
    <Signals.CTRL_BREAK_EVENT: 1>
    <Signals.SIGINT: 2>
    <Signals.SIGILL: 4>
    <Signals.SIGFPE: 8>
    <Signals.SIGSEGV: 11>
    <Signals.SIGTERM: 15>
    <Signals.SIGBREAK: 21>
    <Signals.SIGABRT: 22>

We can use the console API when passed the CTRL_C_EVENT or CTRL_BREAK_EVENT enum. It may be easier to implement this version of os.kill in Python code instead of C. We can add the necessary WinAPI functions to the _winapi module.

BTW, I don't think it would be useful to implement the POSIX signal 0 test. Windows readily recycles process and thread IDs. These values are allocated out of the system's PspCidTable handle table. When a thread or process exits, the associated handle table entry is added to a freelist to be reused. So checking whether a process exists with a given PID is all but meaningless. Maybe the process you're interested in died and a new process was assigned the same ID.

To back that up, the following local kernel debugging session demonstrates that the kernel's PspCidTable is implemented as a handle table.

    Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37)
    [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> os.getpid()
    >>> os.system('kd -kl')

    Microsoft (R) Windows Debugger Version 10.0.10240.9 AMD64
    Copyright (c) Microsoft Corporation. All rights reserved.


    lkd> ;as pid 3004
    lkd> ;as cidtab ((nt!_HANDLE_TABLE *)@@(poi(nt!PspCidTable)))
    lkd> ;as tables ((void **)(${cidtab}->TableCode & ~0x11UI64))
    lkd> ;as tabnum ((${pid} / 4) / 256)
    lkd> ;as eindex ((${pid} / 4) % 256)
    lkd> ;as hentry ((nt!_HANDLE_TABLE_ENTRY *)${tables}[${tabnum}] + ${eindex})
    lkd> ;as ptrbit ((${hentry}->ObjectPointerBits << 4) | (0xffffUI64 << 48))
    lkd> ;as eprobj ((nt!_EPROCESS *)${ptrbit})

eprobj evaluates to the kernel process object that's assigned to the handle table entry based on the given PID. To complete the circle, check that the process object really does have this PID:

    lkd> ?? ${eprobj}->UniqueProcessId
    void * 0x00000000`00000bbc
    lkd> ?? 0xbbc
    int 0n3004

and that the image filename is python.exe:

    lkd> ?? (char *)${eprobj}->ImageFileName
    char * 0xffffe001`647564c8
Date User Action Args
2021-03-20 03:51:30eryksununlinkissue23948 messages
2015-12-10 07:20:11eryksunsetrecipients: + eryksun, jpe, tim.golden, zach.ware, steve.dower
2015-12-10 07:20:10eryksunsetmessageid: <>
2015-12-10 07:20:10eryksunlinkissue23948 messages
2015-12-10 07:20:09eryksuncreate