how do shells relate to kernels?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
com1
Member
Member
Posts: 105
Joined: Sat Apr 28, 2007 11:57 am
Location: TN

how do shells relate to kernels?

Post by com1 »

does the shell of an OS have to be written in the kernel? if not, how does the shell communicate with the kernel in a microkernel environment?



thanks in advance,
oh microsoft, microsoft, what souls you have dismayed
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: how do shells relate to kernels?

Post by Candy »

com1 wrote:does the shell of an OS have to be written in the kernel? if not, how does the shell communicate with the kernel in a microkernel environment?



thanks in advance,
A shell is just an ordinary program with ordinary functions and so on. Make a shell in Minix to find out for yourself.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: how do shells relate to kernels?

Post by Brendan »

Hi,
com1 wrote:does the shell of an OS have to be written in the kernel?
No, and I can't think of any (non-hobby) OS where the shell actually is implemented in the kernel (MS-DOS used "command.com", Windows uses a DOS emulator running "command.com", Linux/UNIX uses Bash or Ash or C-shell or Z-shell or something else, etc).
com1 wrote:if not, how does the shell communicate with the kernel in a microkernel environment?
In a micro-kernel environment, the shell would communicate with something that controls the user interface (e.g. a process responsible for virtual terminals), which (eventually) talks to device drivers.

AFAIK this is the same in UNIX - the shell uses it's stderr, stdout and stdin, which are typically connected to it's parent process (e.g. "term").

The kernel is responsible for the communication between these processes, and in a monolithic system it'd be responsible for the device drivers too (video, keyboard, mouse, etc), but apart from that the kernel has nothing to do with the shell - the shell is just another process as far as the kernel is concerned.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: how do shells relate to kernels?

Post by Colonel Kernel »

Brendan wrote:Windows uses a DOS emulator running "command.com"
For the sake of historical accuracy, I'd like to add that this was only true of Windows 9x/ME and earlier. NT/2k/XP use CMD.EXE, which looks and acts like DOS, but is not a DOS emulator (NTVDM.EXE is the dos emulator, and it can run command.com if you're feeling nostalgic). I think Vista has a new shell ("Powershell", formerly known as "Monad") but I haven't even sneezed in the general direction of Vista yet, so I don't know if this new shell is the default or not.

Some more examples of shells that are not in the kernel -- Explorer.exe on Windows, Finder on the Mac (shells can be graphical too).
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

hmmm...anyone know of a portable shell? like portable to different OS's?
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Post by mathematician »

hckr83 wrote:hmmm...anyone know of a portable shell? like portable to different OS's?
As it has been said, the shell is just another application, and, like all applications, it makes calls to the underlying operating system. You could have a shell which was portable at source code level, provided it didn't contain assembly language, but you would need a compiler which could compile it for the intended OS. If that OS was new, as in, "you've just written it," there is unlikely to be a compiler around to do the job. The only thing which makes the shell different from any other application is that it gets itself loaded automatically immediately after the OS has finished initialising.

By the way, a shell doesn't have to be a command line program. The word "shell" arises from the idea of its being something which wraps itself around the kernel, with the kernel on the inside and you on the outside. Windows primary shell is its GUI (which doesn't nowadays run on top of the command line interface).

Anyway, I imagine that a command line would be the easiest part of the operating system to write. After all, by then you have got a file system, memory manager, i/o to the console....... in fact everything an applications programmer takes for granted. (But unlike most applications programmers, you can go back and implement some more kernel functionality if you need it.)
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

hckr83 wrote:hmmm...anyone know of a portable shell? like portable to different OS's?
Try http://en.wikipedia.org/wiki/Category:Unix_shells. Most just require a standard C library, but can use others e.g. readline etc. From the looks of the articles, dash seems to be one of the simplest.

Regards,
John.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post by Candy »

jnc100 wrote:
hckr83 wrote:hmmm...anyone know of a portable shell? like portable to different OS's?
Try http://en.wikipedia.org/wiki/Category:Unix_shells. Most just require a standard C library, but can use others e.g. readline etc. From the looks of the articles, dash seems to be one of the simplest.
www.sf.net/projects/ncsh -> intended to be portable. It's less than tested, though. It's derived from another project I started (but that was part of a school project), www.sf.net/projects/cdsh. The last one is a bit more tested but uses readline.
Post Reply