UnsupportedProcess.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. htop - UnsupportedProcess.c
  3. (C) 2015 Hisham H. Muhammad
  4. Released under the GNU GPLv2+, see the COPYING file
  5. in the source distribution for its full text.
  6. */
  7. #include "config.h" // IWYU pragma: keep
  8. #include "unsupported/UnsupportedProcess.h"
  9. #include <stdlib.h>
  10. #include "CRT.h"
  11. #include "Process.h"
  12. const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
  13. [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
  14. [PID] = { .name = "PID", .title = "PID", .description = "Process/thread ID", .flags = 0, .pidColumn = true, },
  15. [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
  16. [STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, },
  17. [PPID] = { .name = "PPID", .title = "PPID", .description = "Parent process ID", .flags = 0, .pidColumn = true, },
  18. [PGRP] = { .name = "PGRP", .title = "PGRP", .description = "Process group ID", .flags = 0, .pidColumn = true, },
  19. [SESSION] = { .name = "SESSION", .title = "SID", .description = "Process's session ID", .flags = 0, .pidColumn = true, },
  20. [TTY] = { .name = "TTY", .title = "TTY ", .description = "Controlling terminal", .flags = 0, },
  21. [TPGID] = { .name = "TPGID", .title = "TPGID", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, .pidColumn = true, },
  22. [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, .defaultSortDesc = true,},
  23. [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, .defaultSortDesc = true, },
  24. [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
  25. [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
  26. [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
  27. [ELAPSED] = { .name = "ELAPSED", .title = "ELAPSED ", .description = "Time since the process was started", .flags = 0, },
  28. [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
  29. [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, },
  30. [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, },
  31. [ST_UID] = { .name = "ST_UID", .title = "UID", .description = "User ID of the process owner", .flags = 0, },
  32. [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = " CPU%", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, .defaultSortDesc = true, .autoWidth = true, .autoTitleRightAlign = true, },
  33. [PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, .defaultSortDesc = true, .autoWidth = true, },
  34. [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, .defaultSortDesc = true, },
  35. [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
  36. [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, .defaultSortDesc = true, },
  37. [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
  38. [TGID] = { .name = "TGID", .title = "TGID", .description = "Thread group ID (i.e. process ID)", .flags = 0, .pidColumn = true, },
  39. };
  40. Process* UnsupportedProcess_new(const Machine* host) {
  41. Process* this = xCalloc(1, sizeof(UnsupportedProcess));
  42. Object_setClass(this, Class(UnsupportedProcess));
  43. Process_init(this, host);
  44. return this;
  45. }
  46. void Process_delete(Object* cast) {
  47. Process* super = (Process*) cast;
  48. Process_done(super);
  49. // free platform-specific fields here
  50. free(cast);
  51. }
  52. static void UnsupportedProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) {
  53. const UnsupportedProcess* up = (const UnsupportedProcess*) super;
  54. bool coloring = super->host->settings->highlightMegabytes;
  55. char buffer[256]; buffer[255] = '\0';
  56. int attr = CRT_colors[DEFAULT_COLOR];
  57. size_t n = sizeof(buffer) - 1;
  58. (void) coloring;
  59. (void) n;
  60. switch (field) {
  61. /* Add platform specific fields */
  62. default:
  63. Process_writeField(&up->super, str, field);
  64. return;
  65. }
  66. RichString_appendWide(str, attr, buffer);
  67. }
  68. static int UnsupportedProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) {
  69. const UnsupportedProcess* p1 = (const UnsupportedProcess*)v1;
  70. const UnsupportedProcess* p2 = (const UnsupportedProcess*)v2;
  71. (void) p1;
  72. (void) p2;
  73. switch (key) {
  74. /* Add platform specific fields */
  75. default:
  76. return Process_compareByKey_Base(v1, v2, key);
  77. }
  78. }
  79. const ProcessClass UnsupportedProcess_class = {
  80. .super = {
  81. .super = {
  82. .extends = Class(Process),
  83. .display = Row_display,
  84. .delete = Process_delete,
  85. .compare = Process_compare
  86. },
  87. .isHighlighted = Process_rowIsHighlighted,
  88. .isVisible = Process_rowIsVisible,
  89. .matchesFilter = Process_rowMatchesFilter,
  90. .compareByParent = Process_compareByParent,
  91. .sortKeyString = Process_rowGetSortKey,
  92. .writeField = UnsupportedProcess_rowWriteField
  93. },
  94. .compareByKey = UnsupportedProcess_compareByKey
  95. };