OS2021_Project1.Shell

103 rivejä
3.0 KiB

3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
3 vuotta sitten
  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 PSINFO_VERSION 0
  17. #define TYPE_TASK 'T'
  18. #define TYPE_SYSTEM 'S'
  19. #define TYPE_USER 'U'
  20. #define STATE_RUN 'R'
  21. #define TIMECYCLEKEY 't'
  22. #define ORDERKEY 'o'
  23. #define USED 0x1
  24. #define IS_TASK 0x2
  25. #define IS_SYSTEM 0x4
  26. #define BLOCKED 0x8
  27. #define ORDER_CPU 0
  28. #define ORDER_MEMORY 1
  29. #define ORDER_HIGHEST ORDER_MEMORY
  30. #define TC_BUFFER 1024 /* Size of termcap(3) buffer */
  31. #define TC_STRINGS 200 /* Enough room for cm,cl,so,se */
  32. /* name of cpu cycle types, in the order they appear in /psinfo. */
  33. const char *cputimenames[] = {"user", "ipc", "kernelcall"};
  34. #define CPUTIMENAMES (sizeof(cputimenames) / sizeof(cputimenames[0]))
  35. #define CPUTIME(m, i) (m & (1L << (i)))
  36. struct proc
  37. {
  38. int p_flags;
  39. endpoint_t p_endpoint;
  40. pid_t p_pid;
  41. u64_t p_cpucycles[CPUTIMENAMES];
  42. int p_priority;
  43. endpoint_t p_blocked;
  44. time_t p_user_time;
  45. vir_bytes p_memory;
  46. uid_t p_effuid;
  47. int p_nice;
  48. char p_name[PROC_NAME_LEN + 1];
  49. };
  50. struct tp
  51. {
  52. struct proc *p;
  53. u64_t ticks;
  54. };
  55. /* readline - Get the command line */
  56. char *readline();
  57. /* parseline - Evaluate the command line that the user has just typed in */
  58. int parseline(char *cmdline, char **args);
  59. /* check_redirect - check if the command contains redirection */
  60. int check_redirect(char **args, char *redirect_filename, char **redirect_args);
  61. /* do_redirect - execute redirection command */
  62. int do_redirect(int redirect_flag, char *redirect_filename, char **redirect_args);
  63. /* check_redirect - check if the command contains pipe */
  64. int check_pipe(char **args, char **pipe_arg_1, char **pipe_arg_2);
  65. /* do_pipe - execute pipe command */
  66. int do_pipe(char **pipe_arg_1, char **pipe_arg_2);
  67. /* do_bgfg - fork and execute background/foreground tasks */
  68. int do_bg_fg(char **args, int bg);
  69. /* execute - Execute the command line */
  70. int execute(char *cmdline, char **args);
  71. /* builtin functions - Handle built-in command */
  72. int built_in(char **args);
  73. int builtin_cd(char **args);
  74. int builtin_history(char **args);
  75. int builtin_mytop();
  76. /* mytop routine */
  77. void mytop_memory();
  78. void mytop_CPU();
  79. void get_procs();
  80. void parse_dir();
  81. void parse_file(pid_t pid);
  82. void getkinfo();
  83. void print_procs(struct proc *proc1, struct proc *proc2, int cputimemode);
  84. u64_t cputicks(struct proc *p1, struct proc *p2, int timemode);