jobid = key
		if value['job_state'] == "RUNNING":
			userid = pwd.getpwuid(value[4])[0]
			nodes = value['alloc_node'].split(',')

			if my_host in nodes:
				PiDs[jobid] = []

			a = os.popen('/bin/ps --noheaders -u {0} -o pid,ppid,size,rss,vsize,pcpu,args'.format(userid), 'r')
			for lines in a:
				line = lines.split()
				command = " ".join(line[6:])
				newline = [ line[0], line[1], line[2], line[3], line[4], line[5], command ]
				pid = int(line[0])
				rc, slurm_jobid = pyslurm.slurm_pid2jobid(pid)
				if rc == 0:
					if PiDs.has_key(slurm_jobid):
						PiDs[slurm_jobid].append(newline)
			a.close()

	if len(PiDs) > 0:

		sys.stdout.write("\t<jobs>\n")
		for job, value in PiDs.iteritems():
			sys.stdout.write("\t\t<job>\n")
			sys.stdout.write("\t\t\t<id>{0}</id>\n".format(job))
			for pid in value:
				sys.stdout.write("\t\t\t<process>\n")
				sys.stdout.write("\t\t\t\t<pid>{0}</pid>\n".format(pid[0]))
				sys.stdout.write("\t\t\t\t<ppid>{0}</ppid>\n".format(pid[1]))
示例#2
0
                "r",
            )
            for lines in a:
                line = lines.split()
                command = " ".join(line[6:])
                newline = [
                    line[0],
                    line[1],
                    line[2],
                    line[3],
                    line[4],
                    line[5],
                    command,
                ]
                pid = int(line[0])
                rc, slurm_jobid = pyslurm.slurm_pid2jobid(pid)
                if rc == 0:
                    if slurm_jobid in PiDs:
                        PiDs[slurm_jobid].append(newline)
            a.close()

    if PiDs:
        sys.stdout.write("\t<jobs>\n")
        for job, value in PiDs.items():
            sys.stdout.write("\t\t<job>\n")
            sys.stdout.write("\t\t\t<id>{0}</id>\n".format(job))
            for pid in value:
                sys.stdout.write("\t\t\t<process>\n")
                sys.stdout.write("\t\t\t\t<pid>{0}</pid>\n".format(pid[0]))
                sys.stdout.write("\t\t\t\t<ppid>{0}</ppid>\n".format(pid[1]))
                sys.stdout.write("\t\t\t\t<size>{0}</size>\n".format(pid[2]))