Changeset 65312 in vbox for trunk/src/VBox/ValidationKit/common
- Timestamp:
- Jan 16, 2017 10:22:59 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/common/utils.py
r65196 r65312 844 844 oMyInfo.windowsGrabProcessInfo(oProcess); 845 845 asProcesses.append(oMyInfo); 846 847 elif sOs in [ 'linux', ]: # Not solaris, ps gets more info than /proc/. 846 return asProcesses; 847 848 if sOs in [ 'linux', ]: # Not solaris, ps gets more info than /proc/. 848 849 try: 849 850 asDirs = os.listdir('/proc'); … … 853 854 if sDir.isdigit(): 854 855 asProcesses.append(ProcessInfo(int(sDir),)); 855 856 elif sOs == 'darwin': 857 # Try our best to parse ps output. (Not perfect but does the job most of the time.) 858 try: 859 sRaw = processOutputChecked([ '/bin/ps', '-A', 860 '-o', 'pid=', 861 '-o', 'ppid=', 862 '-o', 'pgid=', 863 '-o', 'sess=', 864 '-o', 'uid=', 865 '-o', 'gid=', 866 '-o', 'comm=' ]); 867 except: 868 return asProcesses; 856 return asProcesses; 857 858 # 859 # The other OSes parses the output from the 'ps' utility. 860 # 861 asPsCmd = [ 862 '/bin/ps', # 0 863 '-A', # 1 864 '-o', 'pid=', # 2,3 865 '-o', 'ppid=', # 4,5 866 '-o', 'pgid=', # 6,7 867 '-o', 'sid=', # 8,9 868 '-o', 'uid=', # 10,11 869 '-o', 'gid=', # 12,13 870 '-o', 'comm=' # 14,15 871 ]; 872 873 if sOs == 'darwin': 874 assert asPsCmd[9] == 'sid='; 875 asPsCmd[9] = 'sess='; 869 876 elif sOs == 'solaris': 870 # Try our best to parse ps output. (Not perfect but does the job most of the time.) 871 try: 872 sRaw = processOutputChecked([ '/usr/bin/ps', '-A', 873 '-o', 'pid=', 874 '-o', 'ppid=', 875 '-o', 'pgid=', 876 '-o', 'sid=', 877 '-o', 'uid=', 878 '-o', 'gid=', 879 '-o', 'comm=' ]); 880 except: 881 return asProcesses; 882 883 for sLine in sRaw.split('\n'): 884 sLine = sLine.lstrip(); 885 if len(sLine) < 7 or not sLine[0].isdigit(): 886 continue; 887 888 iField = 0; 889 off = 0; 890 aoFields = [None, None, None, None, None, None, None]; 891 while iField < 7: 892 # Eat whitespace. 893 while off < len(sLine) and (sLine[off] == ' ' or sLine[off] == '\t'): 894 off += 1; 895 896 # Final field / EOL. 897 if iField == 6: 898 aoFields[6] = sLine[off:]; 899 break; 900 if off >= len(sLine): 901 break; 902 903 # Generic field parsing. 904 offStart = off; 877 asPsCmd[0] = '/usr/bin/ps'; 878 879 try: 880 sRaw = processOutputChecked(asPsCmd); 881 except: 882 return asProcesses; 883 884 for sLine in sRaw.split('\n'): 885 sLine = sLine.lstrip(); 886 if len(sLine) < 7 or not sLine[0].isdigit(): 887 continue; 888 889 iField = 0; 890 off = 0; 891 aoFields = [None, None, None, None, None, None, None]; 892 while iField < 7: 893 # Eat whitespace. 894 while off < len(sLine) and (sLine[off] == ' ' or sLine[off] == '\t'): 905 895 off += 1; 906 while off < len(sLine) and sLine[off] != ' ' and sLine[off] != '\t': 907 off += 1; 908 try: 909 if iField != 3: 910 aoFields[iField] = int(sLine[offStart:off]); 911 else: 912 aoFields[iField] = long(sLine[offStart:off], 16); # sess is a hex address. 913 except: 914 pass; 915 iField += 1; 916 917 if aoFields[0] is not None: 918 oMyInfo = ProcessInfo(aoFields[0]); 919 oMyInfo.iParentPid = aoFields[1]; 920 oMyInfo.iProcGroup = aoFields[2]; 921 oMyInfo.iSessionId = aoFields[3]; 922 oMyInfo.iUid = aoFields[4]; 923 oMyInfo.iGid = aoFields[5]; 924 oMyInfo.sName = aoFields[6]; 925 asProcesses.append(oMyInfo); 896 897 # Final field / EOL. 898 if iField == 6: 899 aoFields[6] = sLine[off:]; 900 break; 901 if off >= len(sLine): 902 break; 903 904 # Generic field parsing. 905 offStart = off; 906 off += 1; 907 while off < len(sLine) and sLine[off] != ' ' and sLine[off] != '\t': 908 off += 1; 909 try: 910 if iField != 3: 911 aoFields[iField] = int(sLine[offStart:off]); 912 else: 913 aoFields[iField] = long(sLine[offStart:off], 16); # sess is a hex address. 914 except: 915 pass; 916 iField += 1; 917 918 if aoFields[0] is not None: 919 oMyInfo = ProcessInfo(aoFields[0]); 920 oMyInfo.iParentPid = aoFields[1]; 921 oMyInfo.iProcGroup = aoFields[2]; 922 oMyInfo.iSessionId = aoFields[3]; 923 oMyInfo.iUid = aoFields[4]; 924 oMyInfo.iGid = aoFields[5]; 925 oMyInfo.sName = aoFields[6]; 926 asProcesses.append(oMyInfo); 926 927 927 928 return asProcesses;
Note:
See TracChangeset
for help on using the changeset viewer.