OpenBSDProcess.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. htop - OpenBSDProcess.c
  3. (C) 2015 Hisham H. Muhammad
  4. (C) 2015 Michael McConville
  5. Released under the GNU GPLv2+, see the COPYING file
  6. in the source distribution for its full text.
  7. */
  8. #include "config.h" // IWYU pragma: keep
  9. #include "openbsd/OpenBSDProcess.h"
  10. #include <stdlib.h>
  11. #include "CRT.h"
  12. #include "Process.h"
  13. #include "RichString.h"
  14. #include "XUtils.h"
  15. const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
  16. [0] = {
  17. .name = "",
  18. .title = NULL,
  19. .description = NULL,
  20. .flags = 0,
  21. },
  22. [PID] = {
  23. .name = "PID",
  24. .title = "PID",
  25. .description = "Process/thread ID",
  26. .flags = 0,
  27. .pidColumn = true,
  28. },
  29. [COMM] = {
  30. .name = "Command",
  31. .title = "Command ",
  32. .description = "Command line (insert as last column only)",
  33. .flags = 0,
  34. },
  35. [STATE] = {
  36. .name = "STATE",
  37. .title = "S ",
  38. .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)",
  39. .flags = 0,
  40. },
  41. [PPID] = {
  42. .name = "PPID",
  43. .title = "PPID",
  44. .description = "Parent process ID",
  45. .flags = 0,
  46. .pidColumn = true,
  47. },
  48. [PGRP] = {
  49. .name = "PGRP",
  50. .title = "PGRP",
  51. .description = "Process group ID",
  52. .flags = 0,
  53. .pidColumn = true,
  54. },
  55. [SESSION] = {
  56. .name = "SESSION",
  57. .title = "SESN",
  58. .description = "Process's session ID",
  59. .flags = 0,
  60. .pidColumn = true,
  61. },
  62. [TTY] = {
  63. .name = "TTY",
  64. .title = "TTY ",
  65. .description = "Controlling terminal",
  66. .flags = 0,
  67. },
  68. [TPGID] = {
  69. .name = "TPGID",
  70. .title = "TPGID",
  71. .description = "Process ID of the fg process group of the controlling terminal",
  72. .flags = 0,
  73. .pidColumn = true,
  74. },
  75. [MINFLT] = {
  76. .name = "MINFLT",
  77. .title = " MINFLT ",
  78. .description = "Number of minor faults which have not required loading a memory page from disk",
  79. .flags = 0,
  80. .defaultSortDesc = true,
  81. },
  82. [MAJFLT] = {
  83. .name = "MAJFLT",
  84. .title = " MAJFLT ",
  85. .description = "Number of major faults which have required loading a memory page from disk",
  86. .flags = 0,
  87. .defaultSortDesc = true,
  88. },
  89. [PRIORITY] = {
  90. .name = "PRIORITY",
  91. .title = "PRI ",
  92. .description = "Kernel's internal priority for the process",
  93. .flags = 0,
  94. },
  95. [NICE] = {
  96. .name = "NICE",
  97. .title = " NI ",
  98. .description = "Nice value (the higher the value, the more it lets other processes take priority)",
  99. .flags = 0,
  100. },
  101. [STARTTIME] = {
  102. .name = "STARTTIME",
  103. .title = "START ",
  104. .description = "Time the process was started",
  105. .flags = 0,
  106. },
  107. [ELAPSED] = {
  108. .name = "ELAPSED",
  109. .title = "ELAPSED ",
  110. .description = "Time since the process was started",
  111. .flags = 0,
  112. },
  113. [PROCESSOR] = {
  114. .name = "PROCESSOR",
  115. .title = "CPU ",
  116. .description = "Id of the CPU the process last executed on",
  117. .flags = 0,
  118. },
  119. [M_VIRT] = {
  120. .name = "M_VIRT",
  121. .title = " VIRT ",
  122. .description = "Total program size in virtual memory",
  123. .flags = 0,
  124. .defaultSortDesc = true,
  125. },
  126. [M_RESIDENT] = {
  127. .name = "M_RESIDENT",
  128. .title = " RES ",
  129. .description = "Resident set size, size of the text and data sections, plus stack usage",
  130. .flags = 0,
  131. .defaultSortDesc = true,
  132. },
  133. [ST_UID] = {
  134. .name = "ST_UID",
  135. .title = "UID",
  136. .description = "User ID of the process owner",
  137. .flags = 0,
  138. },
  139. [PERCENT_CPU] = {
  140. .name = "PERCENT_CPU",
  141. .title = " CPU%",
  142. .description = "Percentage of the CPU time the process used in the last sampling",
  143. .flags = 0,
  144. .defaultSortDesc = true,
  145. .autoWidth = true,
  146. .autoTitleRightAlign = true,
  147. },
  148. [PERCENT_NORM_CPU] = {
  149. .name = "PERCENT_NORM_CPU",
  150. .title = "NCPU%",
  151. .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)",
  152. .flags = 0,
  153. .defaultSortDesc = true,
  154. .autoWidth = true,
  155. },
  156. [PERCENT_MEM] = {
  157. .name = "PERCENT_MEM",
  158. .title = "MEM% ",
  159. .description = "Percentage of the memory the process is using, based on resident memory size",
  160. .flags = 0,
  161. .defaultSortDesc = true,
  162. },
  163. [USER] = {
  164. .name = "USER",
  165. .title = "USER ",
  166. .description = "Username of the process owner (or user ID if name cannot be determined)",
  167. .flags = 0,
  168. },
  169. [TIME] = {
  170. .name = "TIME",
  171. .title = " TIME+ ",
  172. .description = "Total time the process has spent in user and system time",
  173. .flags = 0,
  174. .defaultSortDesc = true,
  175. },
  176. [NLWP] = {
  177. .name = "NLWP",
  178. .title = "NLWP ",
  179. .description = "Number of threads in the process",
  180. .flags = 0,
  181. },
  182. [TGID] = {
  183. .name = "TGID",
  184. .title = "TGID",
  185. .description = "Thread group ID (i.e. process ID)",
  186. .flags = 0,
  187. .pidColumn = true,
  188. },
  189. [PROC_COMM] = {
  190. .name = "COMM",
  191. .title = "COMM ",
  192. .description = "comm string of the process",
  193. .flags = 0,
  194. },
  195. [CWD] = {
  196. .name = "CWD",
  197. .title = "CWD ",
  198. .description = "The current working directory of the process",
  199. .flags = PROCESS_FLAG_CWD,
  200. },
  201. };
  202. Process* OpenBSDProcess_new(const Machine* host) {
  203. OpenBSDProcess* this = xCalloc(1, sizeof(OpenBSDProcess));
  204. Object_setClass(this, Class(OpenBSDProcess));
  205. Process_init(&this->super, host);
  206. return (Process*)this;
  207. }
  208. void Process_delete(Object* cast) {
  209. OpenBSDProcess* this = (OpenBSDProcess*) cast;
  210. Process_done((Process*)cast);
  211. free(this);
  212. }
  213. static void OpenBSDProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
  214. const OpenBSDProcess* op = (const OpenBSDProcess*) super;
  215. char buffer[256]; buffer[255] = '\0';
  216. int attr = CRT_colors[DEFAULT_COLOR];
  217. //size_t n = sizeof(buffer) - 1;
  218. switch (field) {
  219. // add OpenBSD-specific fields here
  220. default:
  221. Process_writeField(&op->super, str, field);
  222. return;
  223. }
  224. RichString_appendWide(str, attr, buffer);
  225. }
  226. static int OpenBSDProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) {
  227. const OpenBSDProcess* p1 = (const OpenBSDProcess*)v1;
  228. const OpenBSDProcess* p2 = (const OpenBSDProcess*)v2;
  229. // remove if actually used
  230. (void)p1; (void)p2;
  231. switch (key) {
  232. // add OpenBSD-specific fields here
  233. default:
  234. return Process_compareByKey_Base(v1, v2, key);
  235. }
  236. }
  237. const ProcessClass OpenBSDProcess_class = {
  238. .super = {
  239. .super = {
  240. .extends = Class(Process),
  241. .display = Row_display,
  242. .delete = Process_delete,
  243. .compare = Process_compare
  244. },
  245. .isHighlighted = Process_rowIsHighlighted,
  246. .isVisible = Process_rowIsVisible,
  247. .matchesFilter = Process_rowMatchesFilter,
  248. .compareByParent = Process_compareByParent,
  249. .sortKeyString = Process_rowGetSortKey,
  250. .writeField = OpenBSDProcess_rowWriteField
  251. },
  252. .compareByKey = OpenBSDProcess_compareByKey
  253. };