diff options
author | Mahadev Konar <mahadev@apache.org> | 2012-10-16 06:13:44 +0000 |
---|---|---|
committer | Mahadev Konar <mahadev@apache.org> | 2012-10-16 06:13:44 +0000 |
commit | b41d25189fd21aa1a12ff398d75e7273f5b40d61 (patch) | |
tree | dcde6261b5344ab719610316b576350f40fc74b3 /ambari-agent | |
parent | 6d894db77e0f1c796c9ea0a6be84d3728fa5a19b (diff) |
AMBARI-852. Improve REST API functionality regarding query and partial response (John Speidel via mahadev)
git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1398662 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'ambari-agent')
-rw-r--r-- | ambari-agent/src/main/python/ambari_agent/ProcUtil.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ambari-agent/src/main/python/ambari_agent/ProcUtil.py b/ambari-agent/src/main/python/ambari_agent/ProcUtil.py new file mode 100644 index 0000000000..d02b331ca6 --- /dev/null +++ b/ambari-agent/src/main/python/ambari_agent/ProcUtil.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python2.6 + +''' +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +''' + +import sys +import os + +def get_proc_status(pid): + pid = int(pid) + path = ("/proc/%d/status" % pid) + if not os.path.exists(path): + return None + status_file = open(path) + lines = status_file.readlines() + for line in lines: + if line.startswith("State:"): + return line.split(":",1)[1].strip().split(' ')[0].split(" ",1)[0] + return None + +if __name__ == '__main__': + state = get_proc_status(sys.argv[1]) + print state |