Reputation: 1682
I am reading about operating systems. I read that when the OS starts, a command interpreter is started as a user process and that when you click in a GUI element, e.g. the desktop symbol of an application, the command to start that application is passed to this command interpreter.
I know command interpreters in the forms of shell or cmd.exe. So does this mean that on Windows when I double click on a desktop icon for, say, word, there is a command interpreter underneath that processes this command? So clicking on the GUI elements equals writing a command in cmd.exe?
And under Windows, what is the name of that process as shown in process explorer?
Upvotes: 0
Views: 1284
Reputation: 58
In linux,Command interpreter takes the command from user and then gives this command to kernel.Command interpreter is also known as shell in linux.There are different shells available in Linux like bash,korn etc...I have implemented simple c base shell as shown below,
/*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] = '\0';
/*return lenth of the line*/
return lenth;
}
Upvotes: 0
Reputation: 36348
Traditionally, at least, the phrase "command interpreter" means only command-line interpreters such as cmd.exe
and if you interpret the phrase that way, the claim is false. When the interface is graphical, such as in Windows, we usually call it a "shell" instead.
The Windows shell is called Explorer, explorer.exe
in Task Manager.
So clicking on the GUI elements equals writing a command in cmd.exe?
They are equivalent, in the sense that they both serve broadly the same function (allowing the user to interface with the operating system) but not identical.
In particular, note that Explorer doesn't work by passing commands to cmd.exe
or vice-versa.
Upvotes: 3