命令解释器在操作系统中的作用
role of command interpreter in operating systems
我正在阅读有关操作系统的内容。我读到当 OS 启动时,命令解释器作为用户进程启动,当您单击 GUI 元素时,例如应用程序的桌面符号,启动该应用程序的命令将传递给此命令解释器。
我知道 shell 或 cmd.exe 形式的命令解释器。那么这是否意味着在 Windows 上,当我双击桌面图标时,比如说,单词,下面有一个命令解释器来处理这个命令?因此,单击 GUI 元素等于在 cmd.exe?
中编写命令
在 Windows 下,进程资源管理器中显示的进程名称是什么?
传统上,至少,短语 "command interpreter" 仅表示命令行解释器,例如 cmd.exe
,如果您以这种方式解释该短语,则该声明是错误的。当界面是图形界面时,例如 Windows,我们通常将其称为 "shell"。
Windowsshell在任务管理器中叫做资源管理器,explorer.exe
So clicking on the GUI elements equals writing a command in cmd.exe?
它们是等效的,因为它们都提供大致相同的功能(允许用户与操作系统交互)但并不完全相同。
请特别注意,Explorer 无法通过将命令传递给 cmd.exe
来工作,反之亦然。
在linux中,命令解释器从用户那里获取命令,然后将此命令交给kernel.Command解释器也称为shell,在linux.There中是不同的shells 在 Linux 中可用,例如 bash、korn 等...我已经实现了简单的 c 基础 shell,如下所示,
/*header*/
#include<stdio.h>
#include<string.h>
#include <signal.h>
#include<stdlib.h>
/*macros*/
/*maximum lenth of the line*/
#define LINE_MAX 10
/*function prototype*/
int getline1(char s[],int lim);
/*main*/
int main()
{
char line[LINE_MAX];/*to store line*/
int len;/*lenth of the input line*/
/*clear the terminal*/
system("clear");
printf("************This is the C shell**********\n");
printf("Enter ctrl+D to exit\n");
/*calls the getline function to get input line*/
while ((len = getline1(line, LINE_MAX)) > 0){
/*if specified command is entered then execute it
*else print command is not found
*/
if(!strcmp(line,"ls"))
system("ls");
else if(!strcmp(line,"pwd"))
system("pwd");
else if(!strcmp(line,"ifconfig"))
system("ifconfig");
else
printf("Command is not found\n");
}
printf("Exiting from shell..\n");
return(0);
}
/**
* @brief getline1 gets the line from user
* param [in] : s is string to store line
* param [in] : lim is maximum lenth of the line
*
* @return 0 fail nonzero otherwise
*/
int getline1(char s[],int lim)
{
/*c is to store the character and lenth is lenth of line*/
int c, lenth;
/*take the characters until EOF or new line is reached*/
for (lenth = 0; lenth < lim-1 && (c=getchar()) != EOF && c!='\n' ; ++lenth)
s[lenth] = c;
/*count the new line character*/
if(s[0] == '\n')
lenth++;
/*assign null at end*/
s[lenth] = '[=10=]';
/*return lenth of the line*/
return lenth;
}
我正在阅读有关操作系统的内容。我读到当 OS 启动时,命令解释器作为用户进程启动,当您单击 GUI 元素时,例如应用程序的桌面符号,启动该应用程序的命令将传递给此命令解释器。
我知道 shell 或 cmd.exe 形式的命令解释器。那么这是否意味着在 Windows 上,当我双击桌面图标时,比如说,单词,下面有一个命令解释器来处理这个命令?因此,单击 GUI 元素等于在 cmd.exe?
中编写命令在 Windows 下,进程资源管理器中显示的进程名称是什么?
传统上,至少,短语 "command interpreter" 仅表示命令行解释器,例如 cmd.exe
,如果您以这种方式解释该短语,则该声明是错误的。当界面是图形界面时,例如 Windows,我们通常将其称为 "shell"。
Windowsshell在任务管理器中叫做资源管理器,explorer.exe
So clicking on the GUI elements equals writing a command in cmd.exe?
它们是等效的,因为它们都提供大致相同的功能(允许用户与操作系统交互)但并不完全相同。
请特别注意,Explorer 无法通过将命令传递给 cmd.exe
来工作,反之亦然。
在linux中,命令解释器从用户那里获取命令,然后将此命令交给kernel.Command解释器也称为shell,在linux.There中是不同的shells 在 Linux 中可用,例如 bash、korn 等...我已经实现了简单的 c 基础 shell,如下所示,
/*header*/
#include<stdio.h>
#include<string.h>
#include <signal.h>
#include<stdlib.h>
/*macros*/
/*maximum lenth of the line*/
#define LINE_MAX 10
/*function prototype*/
int getline1(char s[],int lim);
/*main*/
int main()
{
char line[LINE_MAX];/*to store line*/
int len;/*lenth of the input line*/
/*clear the terminal*/
system("clear");
printf("************This is the C shell**********\n");
printf("Enter ctrl+D to exit\n");
/*calls the getline function to get input line*/
while ((len = getline1(line, LINE_MAX)) > 0){
/*if specified command is entered then execute it
*else print command is not found
*/
if(!strcmp(line,"ls"))
system("ls");
else if(!strcmp(line,"pwd"))
system("pwd");
else if(!strcmp(line,"ifconfig"))
system("ifconfig");
else
printf("Command is not found\n");
}
printf("Exiting from shell..\n");
return(0);
}
/**
* @brief getline1 gets the line from user
* param [in] : s is string to store line
* param [in] : lim is maximum lenth of the line
*
* @return 0 fail nonzero otherwise
*/
int getline1(char s[],int lim)
{
/*c is to store the character and lenth is lenth of line*/
int c, lenth;
/*take the characters until EOF or new line is reached*/
for (lenth = 0; lenth < lim-1 && (c=getchar()) != EOF && c!='\n' ; ++lenth)
s[lenth] = c;
/*count the new line character*/
if(s[0] == '\n')
lenth++;
/*assign null at end*/
s[lenth] = '[=10=]';
/*return lenth of the line*/
return lenth;
}