Skip to content

Commit

Permalink
function to get the pid from the thread id
Browse files Browse the repository at this point in the history
  • Loading branch information
bhnedo committed Jul 17, 2017
1 parent 96cad7d commit 989a5fa
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions kstream/process.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@
# License for the specific language governing permissions and limitations
# under the License.

from kstream.includes.windows cimport UCHAR, ULONG, wchar_t
from kstream.includes.windows cimport UCHAR, ULONG, wchar_t, get_process_id_of_thread, open_thread, close_handle, \
THREAD_QUERY_LIMITED_INFORMATION, HANDLE

cdef enum:
INVALID_PID = 4294967295

cdef struct PROCESS_INFO:
# process identifier
ULONG pid
# process parent identifier
ULONG ppid
# name of the image file
wchar_t* name
wchar_t* name


cdef inline ULONG pid_from_tid(ULONG tid) nogil:
cdef HANDLE thread = open_thread(THREAD_QUERY_LIMITED_INFORMATION,
False,
tid)
if thread != NULL:
pid = get_process_id_of_thread(thread)
close_handle(thread)
return pid
else:
return INVALID_PID

0 comments on commit 989a5fa

Please sign in to comment.