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.

102 regels
2.9 KiB

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