-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.c
66 lines (63 loc) · 1.87 KB
/
shell.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "shell.h"
#include "jobcontrol.h"
job *first_job = NULL;
pid_t shell_pgid;
void jobs_info(job *j);
struct termios shell_tmodes;
int main()
{
shell_pgid = getpgrp();
/* ËÏÍÁÎÄÎÙÊ ÉÎÔÅÒÐÒÅÔÁÔÏÒ ÄÏÌÖÅÎ ÉÇÎÏÒÉÒÏ×ÁÔØ ÓÉÇÎÁÌÙ, Ó×ÑÚÁÎÎÙÅ Ó job control */
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
signal(SIGTSTP, SIG_IGN);
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
char line[MAXLINELEN]; /* allow large command lines */
int njobs;
char prompt[50]; // ÓÔÒÏËÁ-ÐÒÉÇÌÁÛÅÎÉÅ ÎÁ ××ÏÄ
char tmp_line[MAXLINELEN];
sprintf(prompt, "<> ");
/* ÓÏÈÒÁÎÑÅÍ tmodes ÄÌÑ ÛÅÌÌÁ */
tcgetattr (STDIN_FILENO, &shell_tmodes);
while (promptline(prompt, tmp_line, sizeof(tmp_line)) > 0)
{
update_status();
strncpy(line, tmp_line, sizeof(line));
if ((njobs = parseline(line)) <= 0)
{
do_job_notification();
continue;
}
/* ÚÁÐÕÓËÁÅÍ ÚÁÄÁÎÉÑ */
job *j;
for (j = first_job; j; j = j->next)
{
if (!j->launched)
launch_job(j);
}
#ifdef DEBUG
{
job *j;
for (j = first_job; j; j = j->next)
{
printf("new job{\n");
printf("\tjob->pgid: %d\n", j->pgid);
printf("\tstdin: %d, stdout: %d, stderr: %d\n", j->stdin, j->stdout, j->stderr);
process *p;
for (p = j->first_process; p; p = p->next)
{
printf("\tnew process{\n");
printf("\t\tprocess pid: %d\n", p->pid);
for (int i = 0; i < p->nargs; i++)
printf("\t\t\"%s\"\n", p->argv[i]);
printf("\t}\n");
}
printf("\n}\n");
}
}
#endif
do_job_notification();
}
return 0;
}