コード例 #1
0
    def execute(self, args):
        # ignore arguments
        tasks = Proc().tasks
        if args.d:
            tasks = Proc().dead_tasks

        max_key_len = max(3, *[len(i) for i in Proc().content().keys()])
        max_user_len = max(
            3, *[
                len(i.principal.id) for i in Proc().content().values()
                if getattr(i, 'principal', None)
            ])

        self.write("%s    %s%s TIME CMD\n" %
                   ("TID".rjust(max_key_len), "PTID    ".rjust(max_key_len)
                    if args.l else '', "USER   ".ljust(max_user_len)))

        for tid, task in tasks.items():
            ptid = task.ptid
            self.write("%s %s   %s %s %s\n" %
                       (tid.rjust(max_key_len),
                        (ptid + ' ').rjust(max_key_len) if args.l else '',
                        (task.principal.id
                         if task.principal else '-').ljust(max_user_len),
                        datetime.timedelta(0, int(task.uptime)), task.cmdline))
コード例 #2
0
    def find_task(self, tid):
        tasks = Proc().tasks

        if re.match('[0-9]+$', tid):
            return tasks[tid]
        else:
            candidates = []
            for i in tasks.values():
                if tid in str(i.cmdline):
                    candidates.append(i)
            if len(candidates) == 1:
                return candidates[0]

        return None
コード例 #3
0
def find_daemon_in_proc(daemontype):
    for pid, process in Proc().tasks.iteritems():
        if type(process.subject) is daemontype:
            return process.subject