change: Just run the required command and let the exception do the rest
if the process died. Checking first if the process is still alive proofed to be quite error prone, atleast on a rather slow compute node.
This commit is contained in:
		| @@ -31,16 +31,12 @@ frequency = PER_INSTANCE | |||||||
| EXIT_FAIL = 254 | EXIT_FAIL = 254 | ||||||
|  |  | ||||||
| # | # | ||||||
| # Returns the cmdline for the given process id. | # Returns the cmdline for the given process id. In Linux we can use procfs for | ||||||
|  | # this but on BSD there is /usr/bin/procstat. | ||||||
| # | # | ||||||
|  |  | ||||||
| def givecmdline(pid): | def givecmdline(pid): | ||||||
|     # Check if this pid still exists by sending it the harmless 0 signal. |  | ||||||
|     try: |     try: | ||||||
|         os.kill(pid, signal.SIG_DFL) |  | ||||||
|     except OSError: |  | ||||||
|         return None |  | ||||||
|     else: |  | ||||||
|         # Example output from procstat -c 1 |         # Example output from procstat -c 1 | ||||||
|         #   PID COMM             ARGS |         #   PID COMM             ARGS | ||||||
|         #     1 init             /bin/init -- |         #     1 init             /bin/init -- | ||||||
| @@ -51,6 +47,8 @@ def givecmdline(pid): | |||||||
|             return m.group(2) |             return m.group(2) | ||||||
|         else: |         else: | ||||||
|             return util.load_file("/proc/%s/cmdline" % pid) |             return util.load_file("/proc/%s/cmdline" % pid) | ||||||
|  |     except IOError: | ||||||
|  |         return None | ||||||
|  |  | ||||||
| def handle(_name, cfg, _cloud, log, _args): | def handle(_name, cfg, _cloud, log, _args): | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Harm Weites
					Harm Weites