資源簡介
《操作系統—精髓與設計原理》一書中myshell編程項目,代碼寫得很清晰,糾錯能力很強大,實現了基本的內部命令:cd、dir、help、echo、environ等,以及實現文件重定向、后臺處理等功能。附有實驗報告。

代碼片段和文件信息
/*???????操作系統練習1:?myshell.c??
???????????姓名:?楊富強
???????????學院:通信工程?
???????????學號:01051312?
??????????在Ubuntu7.10和cygwin下已經測試通過
*/?
#include?“myshell.h“?
int?main?(int?argc?char?*argv[])
{
????char?buf?[MAX_BUFFER]?pwd?[MAX_ARGS];????//?line?buffer
????char?shell_path[MAX_ARGS]=“shell=“;
????char?readme_path[MAX_ARGS]=“readme_path=“;
????char?newpath[MAX_ARGS*1000];
?????int?len;??
???strcpy(newpathgetenv(“PATH“));
???strcat(newpath“:“);
?????if(strcmp(argv[0]“./myshell“)&&strcmp(argv[0]“myshell“))?
?????????{?????????????????
??????????????len=strlen(argv[0]);??
????????????while(len&&argv[0][len]!=‘/‘)???len--?;?
????????????argv[0][len]=‘\0‘;???????????
???????????strcpy(pwdargv[0]);????
???????????get_fullpath(pwd?argv[0]);??
?????????????printf(“%s\n“pwd);??
????????????}
???
???????else??strcpy(pwd??getenv(“PWD“));????
??????strcat(newpathpwd);???//?strcat(newpathgetenv(“PWD“));?????
?????setenv(“PATH“newpath1);//?add?the?current?working?directory??in?the?“PATH“?environment?variable?to?search?for?the?filename?specified.
???
?????strcat(shell_pathpwd);???//??strcat(shell_path?getenv(“PWD“));
????strcat(shell_path“/myshell“);
????putenv(?shell_path);?//add?the?working?directory??of?myshell?in?the?environment?variables???????????
??????strcat(readme_path?pwd);??//???strcat(readme_path?getenv(“PWD“));//????
???????strcat(readme_path“/readme“);?????????
??????putenv(readme_path);?//???add?the?filepath?of?the?file?“readme“??in?the??environment?variables?see?function??my_help(?)?!?
??????
????if(argc>1)??//?也許用戶直接在終端輸入??./myshell?a.bat??>c.txt?
{
???strcpy(buf“myshell?“);
???int?i;
???for(i=1;i ???{
???strcat(bufargv[i]);
???????strcat(buf“??“);
???}
???Execute(buf);//?execute?this?command,??執行這個批處理命令
}
else??//?如果用戶在終端輸入?./myshell
{
???my_clear(?);
???????????fprintf(stderr?“Welcome?Enter?myshell!\nType?\“help\“?to?see?the?help?information.\n“);??????????
???my_shell(stdinNULLNULL);
?}
????return?0?;?
}????//?end??function?“main“?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????188??2008-06-17?12:39??myshell_for_linux\makefile
?????文件???????2118??2008-06-17?12:39??myshell_for_linux\myshell.c
?????文件???????2265??2008-06-17?12:39??myshell_for_linux\myshell.h
?????文件??????11840??2008-06-17?12:39??myshell_for_linux\readme
?????文件??????40643??2008-06-17?12:39??myshell_for_linux\utility.c
?????文件?????371200??2009-04-27?14:29??操作系統實驗報告.doc
?????目錄??????????0??2010-11-02?23:24??myshell_for_linux
-----------?---------??----------?-----??----
???????????????428254????????????????????7
- 上一篇:WEBRTC多人視頻通話
- 下一篇:ubuntu USB驅動
評論
共有 條評論