OS2021_Project1.Shell
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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