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
    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
    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))
    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))
Beispiel #5
0
    def register(self, d, args, command_line, ptid=None):
        subj = yield defer.maybeDeferred(self.subject_from_raw, args)

        # XXX: for some reason, when I let subject to be a generator instance, I get an empty
        # generator in the ComputeTasks container, while it magically works when I save it as a tuple
        # under item.subject
        if type(subj) is proxy.PersistentProxy:
            subj = subj.remove_persistent_proxy()
        assert type(subj) is tuple, "subject of '%s' must be a tuple, got %s" % (self.name, type(subj))

        self.pid = Proc.register(d, subj, command_line, ptid, write_buffer=self.write_buffer,
                                 principal=self.protocol.principal)
        defer.returnValue(self.pid)
    def register(self, d, args, command_line, ptid=None):
        subj = yield defer.maybeDeferred(self.subject_from_raw, args)

        # XXX: for some reason, when I let subject to be a generator instance, I get an empty
        # generator in the ComputeTasks container, while it magically works when I save it as a tuple
        # under item.subject
        if type(subj) is proxy.PersistentProxy:
            subj = subj.remove_persistent_proxy()
        assert type(
            subj) is tuple, "subject of '%s' must be a tuple, got %s" % (
                self.name, type(subj))

        self.pid = Proc.register(d,
                                 subj,
                                 command_line,
                                 ptid,
                                 write_buffer=self.write_buffer,
                                 principal=self.protocol.principal)
        defer.returnValue(self.pid)
Beispiel #7
0
def find_daemon_in_proc(daemontype):
    for pid, process in Proc().tasks.iteritems():
        if type(process.subject) is daemontype:
            return process.subject
Beispiel #8
0
 def unregister(self):
     Proc.unregister(self.pid)
 def unregister(self):
     Proc.unregister(self.pid)