OS2021_Project1.Shell
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

95 行
2.8 KiB

  1. #pragma once
  2. #define CMDLINE_MAX_SIZE 1024 /* max length of a single command line */
  3. #define ARGS_MAX_QUANTITY 128 /* max args on a command line */
  4. #define BUFFER_MAX_SIZE 64 /* max size of a buffer which contains parsed arguments */
  5. #define CMDLINE_DIV ' \t\r\n\a'
  6. #define CMDLINE_HISTORY_MAX_QUANTITY 256
  7. #define JOBS_MAX_QUANTITY 16
  8. #define PATH_MAX_SIZE 256
  9. #define LS_BUF_SIZE 1024
  10. #define REDIRECT_FILENAME_MAX_SIZE 64 /* redirection filename */
  11. #define REDIRECT_ARG_MAX_SIZE 16 /* redirection argument */
  12. #define REDIRECT_NO 0 /* no redirection */
  13. #define REDIRECT_OUT 1 /* redirect output */
  14. #define REDIRECT_IN 2 /* redirect input */
  15. #define _PATH_PROC "/proc/"
  16. #define SLOT_NR(e) (_ENDPOINT_P(e) + nr_tasks)
  17. #define TIMECYCLEKEY 't'
  18. #define ORDERKEY 'o'
  19. #define USED 0x1
  20. #define IS_TASK 0x2
  21. #define IS_SYSTEM 0x4
  22. #define BLOCKED 0x8
  23. #define CPUTIMENAMES (sizeof(cputimenames) / sizeof(cputimenames[0]))
  24. #define CPUTIME(m, i) (m & (1L << (i)))
  25. /* process info */
  26. struct proc
  27. {
  28. int p_flags;
  29. endpoint_t p_endpoint;
  30. pid_t p_pid;
  31. u64_t p_cpucycles[CPUTIMENAMES];
  32. int p_priority;
  33. endpoint_t p_blocked;
  34. time_t p_user_time;
  35. vir_bytes p_memory;
  36. uid_t p_effuid;
  37. int p_nice;
  38. char p_name[PROC_NAME_LEN + 1];
  39. };
  40. struct tp
  41. {
  42. struct proc *p;
  43. u64_t ticks;
  44. };
  45. /* readline - Get the command line */
  46. char *readline();
  47. /* parseline - Evaluate the command line that the user has just typed in */
  48. int parseline(char *cmdline, char **args);
  49. /* check_redirect - check if the command contains redirection */
  50. int check_redirect(char **args, char *redirect_filename, char **redirect_args);
  51. /* do_redirect - execute redirection command */
  52. int do_redirect(int redirect_flag, char *redirect_filename, char **redirect_args);
  53. /* check_redirect - check if the command contains pipe */
  54. int check_pipe(char **args, char **pipe_arg_1, char **pipe_arg_2);
  55. /* do_pipe - execute pipe command */
  56. int do_pipe(char **pipe_arg_1, char **pipe_arg_2);
  57. /* do_bgfg - fork and execute background/foreground tasks */
  58. int do_bg_fg(char **args, int bg);
  59. /* execute - Execute the command line */
  60. int execute(char *cmdline, char **args);
  61. /* builtin functions - Handle built-in command */
  62. int built_in(char **args);
  63. int builtin_cd(char **args);
  64. int builtin_history(char **args);
  65. int builtin_mytop();
  66. int mytop_memory();
  67. /*********** mytop_CPU part ***********/
  68. void getkinfo(void);
  69. void get_procs(void);
  70. void parse_dir(void);
  71. void parse_file(pid_t pid);
  72. void print_procs(int maxlines, struct proc *proc1, struct proc *proc2, int cputimemode);
  73. u64_t cputicks(struct proc *p1, struct proc *p2, int timemode);
  74. char *cputimemodename(int cputimemode);
  75. void print_proc(struct tp *tp, u64_t total_ticks);
  76. struct tp *lookup(endpoint_t who, struct tp *tptab, int np);