Esempio n. 1
0
def main():
    arguments = docopt(__doc__)
    query = arguments['<query>']
    kill_options = arguments['<kill_option>']

    pids = get_pids(query)
    if not pids:
        print 'No process found.'
        return

    print 'PIDs found: {0}'.format(' '.join(pids))

    kill_args = list(kill_options) + pids

    print_and_exec(clom.kill(*kill_args))

    pids = get_pids(query)
    if not pids:
        print 'Killed !'
        return

    print 'Remaining processes:'

    try:
        clom.ps(pid=','.join(pids), format='pid,user,cmd').shell.execute()
    except CommandError as e:
        # Return code 1 for ps means no process was found.
        if e.return_code == 1:
            pass
Esempio n. 2
0
def ack_ps(query, pid_only=False):
    (ps_args, ps_opts) = (PS_ARGS, PS_OPTS) if not pid_only else (PS_PID_ONLY_ARGS, PS_PID_ONLY_OPTS)

    ps = clom.ps(*ps_args, **ps_opts)
    grep_filter = clom.grep(query, **GREP_FILTER_OPTS)
    grep_exclude_self = clom.grep('\({0}\|grep\)'.format(os.getpid()), **GREP_EXCLUDE_SELF_OPTS)

    cmd = ps.pipe_to(grep_filter.pipe_to(grep_exclude_self))

    lines = tuple()
    try:
        lines = cmd.shell.iter()
    except CommandError as e:
        # Return code 1 for grep means nothing was found.
        if e.return_code == 1:
            pass

    if pid_only:
        lines = (l.strip().split()[0] for l in lines)

    return lines