-
大小: 3KB文件類型: .c金幣: 1下載: 0 次發(fā)布日期: 2021-05-07
- 語言: 其他
- 標簽: 操作系統(tǒng)??
資源簡介
1.在linux中實現(xiàn)一個命令執(zhí)行程序doit,它執(zhí)行命令行參數(shù)中的命令,之后統(tǒng)計
1)命令執(zhí)行占用的CPU時間(包括用戶態(tài)和系統(tǒng)態(tài)時間,以毫秒為單位),
2)命令執(zhí)行的時間,
3)進程被搶占的次數(shù),
4)進程主動放棄CPU的次數(shù),
5)進程執(zhí)行過程中發(fā)生缺頁的次數(shù)
代碼片段和文件信息
#include
#include
#include?
#include
#include
#define?NDEBUG
#define?MAX_CMD_LEN?256//the?max?length?of?shell?commands
#define?MAX_TOKEN_NUM?80//the?largest?number?of?tokens
#define?HOME?“/“//home?directory?of?shell
void?printCwd(){/*{{{*/
long?size;
char?*buf;
char?*cwd;
size=pathconf(“.“_PC_PATH_MAX);
if((buf=(char?*)malloc((size_t)size))!=NULL)
cwd=getcwd(buf(size_t)size);
printf(“%s$“cwd);
}/*}}}*/
void?myshell(){/*{{{*/
printCwd();
char?cmd[MAX_CMD_LEN+1];//store?a?command?line
char?*token[MAX_TOKEN_NUM+1];//store?tokens?from?command
int?token_num;//number?of?tokens
int?DaemonToggle=0;//daemon?toggle
int?i=-1;
do{
i++;
cmd[i]=getchar();
}while(cmd[i]!=‘\n‘&&i<=MAX_CMD_LEN);
cmd[i]=‘\0‘;
if(i==0){//no?input
return;
}
#ifndef?NDEBUG
printf(“DEBUG--%d\t\tcommand:%s\n“__LINE__cmd);
#endif
token[0]=strtok(cmd“?“);
for(i=1;token[i-1]!=NULL&&i token[i]=strtok(NULL“?“);
#ifndef?NDEBUG
printf(“DEBUG--%d\t\ttoken[%d]:%s\n“__LINE__itoken[i]);
#endif
}
if(token[i-1]==NULL){
token_num=i-1;
}
else{
token[i]=NULL;
token_num=i;
}
if(strcmp(token[token_num-1]“&“)==0)
DaemonToggle=1;
else?
DaemonToggle=0;
#ifndef?NDEBUG
printf(“DEBUG--%d\t\ttokens:“__LINE__);
for(i=0;token[i]!=NULL;i++)
printf(“%s?“token[i]);
printf
- 上一篇:32位Visio一鍵到底式安裝包
- 下一篇:智能手環(huán)硬件原理圖
評論
共有 條評論