1 import os, os.path
2
3
4
6 """
7 Return memory status for the current process.
8 Figures are returned in number of pages.
9
10 @param key: which memory type to ask for; possible values are 'total',
11 'resident', 'share', 'text', 'lib' and 'data'.
12 @type key: string
13 @rtype: int
14 """
15 mask = {'total': 0,
16 'resident': 1,
17 'share': 2,
18 'text': 3,
19 'lib': 4,
20 'data': 5}
21
22 statm_path = '/proc/self/statm'
23 f = open(statm_path)
24 data = f.read()
25 f.close()
26
27 data = data.split(' ')
28
29 return int(data[mask[key]])
30
32 """
33 Return the list of file descriptors opened by the current process.
34
35 @rtype: list of string
36 """
37 fd_path = '/proc/self/fd'
38 fds = os.listdir(fd_path)
39
40 def get_path_from_fd(fd):
41 path = os.path.join(fd_path, fd)
42 try:
43 path = os.readlink(path)
44 except:
45 return None
46 return path
47
48 fds = map(get_path_from_fd, fds)
49 fds = filter(lambda e: e != None, fds)
50
51 return fds
52
54 """
55 Return the number of threads of the current process.
56
57 @rtype: int
58 """
59 tasks_path = '/proc/self/task'
60 tasks = os.listdir(tasks_path)
61 return len(tasks)
62