forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpscheck.py
60 lines (47 loc) · 1.36 KB
/
pscheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Script Name : pscheck.py
# Author : Craig Richards
# Created : 19th December 2011
# Last Modified : 17th June 2013
# Version : 1.1
# Modifications : 1.1 - 17/06/13 - CR - Changed to functions, and check os before running the program
# Description : Process check on Nix boxes, diplsay formatted output from ps command
import os
import string
import commands
try:
input = raw_input
except NameError:
pass
def ps():
program = input("Enter the name of the program to check: ")
try:
# perform a ps command and assign results to a list
output = commands.getoutput("ps -f|grep " + program)
proginfo = string.split(output)
# display results
print(
"\n\
Full path:\t\t",
proginfo[5],
"\n\
Owner:\t\t\t",
proginfo[0],
"\n\
Process ID:\t\t",
proginfo[1],
"\n\
Parent process ID:\t",
proginfo[2],
"\n\
Time started:\t\t",
proginfo[4],
)
except:
print("There was a problem with the program.")
def main():
if os.name == "posix": # Unix/Linux/MacOS/BSD/etc
ps() # Call the function
elif os.name in ("nt", "dos", "ce"): # if the OS is windows
print("You need to be on Linux or Unix to run this")
if __name__ == "__main__":
main()