<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from ctypes import cdll , pointer , c_uint , c_ubyte , c_ulong <EOL> from struct import pack <EOL> import six <EOL> __all__ = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> CTL_KERN = <NUM_LIT:1> <EOL> KERN_PROC = <NUM_LIT> <EOL> KERN_PROC_PID = <NUM_LIT:1> <EOL> KERN_PROC_PGRP = <NUM_LIT:2> <EOL> MAXCOMLEN = <NUM_LIT:16> <EOL> P_COMM_OFFSET = <NUM_LIT> <EOL> LIBC = None <EOL> def _init ( ) : <EOL> """<STR_LIT>""" <EOL> global LIBC <EOL> if LIBC is None : <EOL> LIBC = cdll . LoadLibrary ( '<STR_LIT>' ) <EOL> def get_proc_info ( pid ) : <EOL> """<STR_LIT>""" <EOL> _init ( ) <EOL> mib = ( c_uint * <NUM_LIT:4> ) ( CTL_KERN , KERN_PROC , KERN_PROC_PID , pid ) <EOL> oldlen = c_ulong ( ) <EOL> oldlenp = pointer ( oldlen ) <EOL> r = LIBC . sysctl ( mib , len ( mib ) , None , oldlenp , None , <NUM_LIT:0> ) <EOL> if r : <EOL> return <EOL> reslen = oldlen . value <EOL> old = ( c_ubyte * reslen ) ( ) <EOL> oldp = pointer ( old ) <EOL> r = LIBC . sysctl ( mib , len ( mib ) , old , oldlenp , None , <NUM_LIT:0> ) <EOL> if r : <EOL> return <EOL> return old [ : reslen ] <EOL> def get_proc_name ( pid ) : <EOL> """<STR_LIT>""" <EOL> proc_kinfo = get_proc_info ( pid ) <EOL> if not proc_kinfo : <EOL> return <EOL> p_comm_range = proc_kinfo [ P_COMM_OFFSET : P_COMM_OFFSET + MAXCOMLEN + <NUM_LIT:1> ] <EOL> p_comm_raw = '<STR_LIT>' . join ( six . unichr ( c ) for c in p_comm_range ) <EOL> p_comm = p_comm_raw . split ( '<STR_LIT>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> return p_comm </s>
