OS2021_Project1.Shell
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.7 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 UNDF 0 /* undefined */
  11. #define FG 1 /* running in foreground */
  12. #define BG 2 /* running in background */
  13. #define ST 3 /* stopped */
  14. #define NO_REDRT 0 /* no redirection */
  15. #define OUT_REDRT 1 /* the latter is output */
  16. #define IN_REDRT 2 /* the former is input */
  17. /* job_t - The job struct */
  18. struct job_t
  19. {
  20. pid_t pid; /* job PID */
  21. int jid; /* job ID [1, 2, ...] */
  22. int state; /* UNDEF, BG, FG, or ST */
  23. char cmdline[CMDLINE_MAX_SIZE]; /* command line */
  24. };
  25. /* readline - Get the command line */
  26. char *readline();
  27. /* parseline - Evaluate the command line that the user has just typed in */
  28. int parseline(char *cmdline, char **args);
  29. /* redirect - Judge if the command contains redirection */
  30. int redirect(char **args, char *redirect_file, char **redirect_args);
  31. /* execute - Execute the command line */
  32. int execute(char *cmdline, char **args);
  33. /* builtin functions - Handle built-in command */
  34. int built_in(char **args);
  35. int builtin_cd(char **args);
  36. int builtin_history(char **args);
  37. int builtin_jobs(char **args);
  38. int builtin_mytop(char **args);
  39. /* do_bgfg - Execute background/foregroung tasks */
  40. int do_bgfg(char **args);
  41. /* waitfg - Wait foreground jobs to finish */
  42. void waitfg(pid_t pid);
  43. /* initjobs - Initialize the job list */
  44. void initjobs(struct job_t *jobs);
  45. /* addjob - Add jobs to joblist */
  46. int addjob(struct job_t *jobs, pid_t pid, int state, char *cmdline);
  47. /* listjobs - Print the job list */
  48. void listjobs(struct job_t *jobs);
  49. /* deletejob - Delete a job whose PID=pid from the job list */
  50. int deletejob(struct job_t *jobs, pid_t pid);
  51. /* clearjob - Clear the entries in a job struct */
  52. void clearjob(struct job_t *job);
  53. /* pide2jid - Map process ID to job ID*/
  54. int pid2jid(pid_t pid);
  55. /* fgpid - Return PID of current foreground job, 0 if no such job */
  56. pid_t fgpid(struct job_t *jobs);
  57. /* getjobpid - Find a job (by PID) on the job list */
  58. struct job_t *getjobpid(struct job_t *jobs, pid_t pid);
  59. /* getjobjid - Find a job (by JID) on the job list */
  60. struct job_t *getjobjid(struct job_t *jobs, int jid);
  61. /* maxjid - Returns largest allocated job ID */
  62. int maxjid(struct job_t *jobs);
  63. /* Signal - wrapper for the sigaction function */
  64. typedef void handler_t(int);
  65. handler_t *Signal(int signum, handler_t *handler);
  66. /*
  67. * sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
  68. * a child job terminates (becomes a zombie), or stops because it
  69. * received a SIGSTOP or SIGTSTP signal. The handler reaps all
  70. * available zombie children, but doesn't wait for any other
  71. * currently running children to terminate.
  72. */
  73. void sigchld_handler(int signal);
  74. /*
  75. * sigint_handler - The kernel sends a SIGINT to the shell whenver the
  76. * user types ctrl-c at the keyboard. Catch it and send it along
  77. * to the foreground job.
  78. */
  79. void sigint_handler(int signal);
  80. /*
  81. * sigtstp_handler - The kernel sends a SIGTSTP to the shell whenever
  82. * the user types ctrl-z at the keyboard. Catch it and suspend the
  83. * foreground job by sending it a SIGTSTP.
  84. */
  85. void sigtstp_handler(int signal);
  86. /*
  87. * sigquit_handler - The driver program can gracefully terminate the
  88. * child shell by sending it a SIGQUIT signal.
  89. */
  90. void sigquit_handler(int signal);