OS2021_Project1.Shell
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.9 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  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 CPUTIME(m, i) (m & (1L << (i)))
  24. #define ORDER_CPU 0
  25. #define ORDER_MEMORY 1
  26. #define ORDER_HIGHEST ORDER_MEMORY
  27. /* process info */
  28. struct proc
  29. {
  30. int p_flags;
  31. endpoint_t p_endpoint;
  32. pid_t p_pid;
  33. u64_t p_cpucycles[CPUTIMENAMES];
  34. int p_priority;
  35. endpoint_t p_blocked;
  36. time_t p_user_time;
  37. vir_bytes p_memory;
  38. uid_t p_effuid;
  39. int p_nice;
  40. char p_name[PROC_NAME_LEN + 1];
  41. };
  42. struct tp
  43. {
  44. struct proc *p;
  45. u64_t ticks;
  46. };
  47. /* readline - Get the command line */
  48. char *readline();
  49. /* parseline - Evaluate the command line that the user has just typed in */
  50. int parseline(char *cmdline, char **args);
  51. /* check_redirect - check if the command contains redirection */
  52. int check_redirect(char **args, char *redirect_filename, char **redirect_args);
  53. /* do_redirect - execute redirection command */
  54. int do_redirect(int redirect_flag, char *redirect_filename, char **redirect_args);
  55. /* check_redirect - check if the command contains pipe */
  56. int check_pipe(char **args, char **pipe_arg_1, char **pipe_arg_2);
  57. /* do_pipe - execute pipe command */
  58. int do_pipe(char **pipe_arg_1, char **pipe_arg_2);
  59. /* do_bgfg - fork and execute background/foreground tasks */
  60. int do_bg_fg(char **args, int bg);
  61. /* execute - Execute the command line */
  62. int execute(char *cmdline, char **args);
  63. /* builtin functions - Handle built-in command */
  64. int built_in(char **args);
  65. int builtin_cd(char **args);
  66. int builtin_history(char **args);
  67. int builtin_mytop();
  68. int mytop_memory();
  69. /*********** mytop_CPU part ***********/
  70. void getkinfo(void);
  71. void get_procs(void);
  72. void parse_dir(void);
  73. void parse_file(pid_t pid);
  74. void print_procs(int maxlines, struct proc *proc1, struct proc *proc2, int cputimemode);
  75. u64_t cputicks(struct proc *p1, struct proc *p2, int timemode);
  76. char *cputimemodename(int cputimemode);
  77. void print_proc(struct tp *tp, u64_t total_ticks);
  78. struct tp *lookup(endpoint_t who, struct tp *tptab, int np);
  79. int cmp_procs(const void *v1, const void *v2);