()
List info of all currently running processes emulating ps aux
    output.
List info of all currently running processes emulating ps aux
    output.
List info of all currently running processes emulating ps aux output .
def test():  # pragma: no cover
    """List info of all currently running processes emulating ps aux
    output.
    """
    import datetime

    today_day = datetime.date.today()
    templ = "%-10s %5s %4s %4s %7s %7s %-13s %5s %7s  %s"
    attrs = ['pid', 'cpu_percent', 'memory_percent', 'name', 'cpu_times',
             'create_time', 'memory_info']
    if _POSIX:
        attrs.append('uids')
        attrs.append('terminal')
    print(templ % ("USER", "PID", "%CPU", "%MEM", "VSZ", "RSS", "TTY",
                   "START", "TIME", "COMMAND"))
    for p in process_iter():
        try:
            pinfo = p.as_dict(attrs, ad_value='')
        except NoSuchProcess:
            pass
        else:
            if pinfo['create_time']:
                ctime = datetime.datetime.fromtimestamp(pinfo['create_time'])
                if ctime.date() == today_day:
                    ctime = ctime.strftime("%H:%M")
                else:
                    ctime = ctime.strftime("%b%d")
            else:
                ctime = ''
            cputime = time.strftime("%M:%S",
                                    time.localtime(sum(pinfo['cpu_times'])))
            try:
                user = p.username()
            except Error:
                user = ''
            if _WINDOWS and '\\' in user:
                user = user.split('\\')[1]
            vms = pinfo['memory_info'] and \
                int(pinfo['memory_info'].vms / 1024) or '?'
            rss = pinfo['memory_info'] and \
                int(pinfo['memory_info'].rss / 1024) or '?'
            memp = pinfo['memory_percent'] and \
                round(pinfo['memory_percent'], 1) or '?'
            print(templ % (
                user[:10],
                pinfo['pid'],
                pinfo['cpu_percent'],
                memp,
                vms,
                rss,
                pinfo.get('terminal', '') or '?',
                ctime,
                cputime,
                pinfo['name'].strip() or '?'))
def test ( ) : # pragma: no cover import datetime today_day = datetime . date . today ( ) templ = "%-10s %5s %4s %4s %7s %7s %-13s %5s %7s  %s" attrs = [ 'pid' , 'cpu_percent' , 'memory_percent' , 'name' , 'cpu_times' , 'create_time' , 'memory_info' ] if _POSIX : attrs . append ( 'uids' ) attrs . append ( 'terminal' ) print ( templ % ( "USER" , "PID" , "%CPU" , "%MEM" , "VSZ" , "RSS" , "TTY" , "START" , "TIME" , "COMMAND" ) ) for p in process_iter ( ) : try : pinfo = p . as_dict ( attrs , ad_value = '' ) except NoSuchProcess : pass else : if pinfo [ 'create_time' ] : ctime = datetime . datetime . fromtimestamp ( pinfo [ 'create_time' ] ) if ctime . date ( ) == today_day : ctime = ctime . strftime ( "%H:%M" ) else : ctime = ctime . strftime ( "%b%d" ) else : ctime = '' cputime = time . strftime ( "%M:%S" , time . localtime ( sum ( pinfo [ 'cpu_times' ] ) ) ) try : user = p . username ( ) except Error : user = '' if _WINDOWS and '\\' in user : user = user . split ( '\\' ) [ 1 ] vms = pinfo [ 'memory_info' ] and int ( pinfo [ 'memory_info' ] . vms / 1024 ) or '?' rss = pinfo [ 'memory_info' ] and int ( pinfo [ 'memory_info' ] . rss / 1024 ) or '?' memp = pinfo [ 'memory_percent' ] and round ( pinfo [ 'memory_percent' ] , 1 ) or '?' print ( templ % ( user [ : 10 ] , pinfo [ 'pid' ] , pinfo [ 'cpu_percent' ] , memp , vms , rss , pinfo . get ( 'terminal' , '' ) or '?' , ctime , cputime , pinfo [ 'name' ] . strip ( ) or '?' ) )