?? change.c
字號:
#include "ysh.h"
#include "extern.h"
void ctrl_z()
{
NODE *p;
int i=1;
if (pid1==0)
goto out; /*前臺沒有工作*/
/*改變鏈表中的相應節點的狀態*/
if (head!=NULL) { /*鏈表不為空*/
p=head;
/*遍歷鏈表,看該工作是否已經在鏈表中*/
while (p->pid!=pid1&&p->link!=NULL)
p=p->link;
if (p->pid==pid1) /*工作已在鏈表中*/
{
strcpy(p->state,"stopped");
}
else
{ /*工作不在鏈表中*/
add_node(input,pid1); /*增加新節點*/
strcpy(end->state,"stopped"); /*設置節點狀態*/
}
}
else
{ /*連標為空*/
add_node(input,pid1); /*增加新節點*/
strcpy(end->state,"stopped"); /*設置節點狀態*/
}
sig_z=1; /*sig_z標志置一,del_node()函數中不用刪除節點*/
kill(pid1,SIGSTOP); /*發送SIGSTOP信號給正在前臺運行的工作,將其停止*/
for (p=head;p->pid!=pid1;p=p->link) /*顯示提示信息*/
i++;
printf("[%d]\t%s\t%s\n",i,end->state,end->cmd);
pid1=0;
out: return;
}
void bg_cmd(int job_num)
{
NODE *p;
int i=0;
p=head;
/*根據作業號,遍歷鏈表,找到指定節點*/
for (i=1;i<job_num;i++)
p=p->link;
kill(p->pid,SIGCONT); /*向對應工作發送SIGCONT信號,使其在后臺運行*/
strcpy(p->state,"running"); /*修改對應節點狀態*/
}
void fg_cmd(int job_num)
{
NODE *p;
int i=0;
p=head;
/*根據作業號,遍歷鏈表,找到指定節點*/
for (i=1;i<job_num;i++)
p=p->link;
strcpy(p->state,"running"); /*修改對應節點狀態*/
strcpy(input,p->cmd); /*將命令名復制到input中,為下一次按下ctrl-z作準備*/
pid1=p->pid; /*獲取該節點對應工作的進程號*/
signal(SIGTSTP,ctrl_z); /*設置signal()信號,為下一次按下ctrl-z作準備*/
kill(p->pid,SIGCONT); /*向對應工作發送SIGCONT信號,使其運行*/
waitpid(p->pid,NULL,0); /*父進程等待前臺進程的運行*/
}
void up_history()
{
if (envhis.start==envhis.end) { /*循環數組為空*/
printf("No history command!\nysh@/root/ysh> ");
} else if (envhis.start<envhis.end) { /*start<end時*/
if (history_number > envhis.start)
printf("%s\nysh@/root/ysh> ",envhis.his_cmd[history_number]);
else
printf("That's all!\nysh@/root/ysh> ");
}else { /*start>end時*/
if (history_number >= 0)
printf("%s\nysh@/root/ysh> ",envhis.his_cmd[history_number]);
else {
if ((history_number + HISNUM) > envhis.start)
printf("%s\nysh@/root/ysh> ",envhis.his_cmd[history_number + HISNUM]);
else
printf("That's all!\nysh@/root/ysh> ");
}
}
history_number--;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -