programming a linux shell using the c programming language
hi every one. well straight to the point. am trying to build a simple linux shell(command line) using the c programming line and cygwin on windows machine. the shell will implement a few easy linux commands like ,cd, ls, pwd, using child processes and fork() function i guess- but i couldnt even make the cursor appear yet on my shell so far!
any help or form of assistance provided is greatly appreciated in advance. reply ASAP thanks. |
How about and example (taken from Chapter 6, Stephen G. Kochan, Patrick H. Wood, Topics in C Programming, rev. ed., 1991):
Code:
#include <stdio.h> And a second example, also for Chapter 6 of the same work: Code:
#include <stdio.h> You might want to look around for a newer edition of Topics; it's an excellent learning-by-example work. Hope this helps some. |
heey, i dont know who you are but i definitely know that you have gotten me going. Thanks a great deal!! now i guess i have no excuses!! :) let me get on with the fiddling and i will let you know as i proceed!
|
Yer welcome -- you might want to pick up a copy of that book: full of working, useful examples and well written. Amazon is a good place to look.
Best of luck with it. |
I think it is helpful to think of a shell as a way to expose kernel/system functionality to the end-user. Most of the things a typical shell does map directly, sometimes a bit indirectly, to core system functions, such as launching process, opening/reading/writing files & devices, setting process state like current working directory & the shell's environment, etc. On top of all of that is the built-in programming/scripting capability, which isn't completely necessary, but is a convenience.
I suggest that you use readline() from libreadline as the basis for your commandline processing. --- rod. |
i guess i have to buy it from amazon. tried looking out for pdfs. no luck so far. so, to amazon i go!
|
thanks
thanks alot guys, am almost done with my little shell. but now i have to implement the "batch mode". ideeaaass? :)
|
You'll need to ask your teacher what they mean by 'batch mode' as *nix doesn't actually have that concept....
Possibly they mean cron http://www.adminschoice.com/crontab-quick-reference ? |
well, i hear the shell wont then display a prompt when in this mode. it will just read the commands from a pre-written batch file and then simply display the commands and their out put. to activate or enter this mode i shoud type [batchfile] on the command prompt where "batchFile" is the name of the batch file prewritten.
|
Ok, that sounds more like reading and acting upon a shell file aka script file, which would make sense.
All a shell/script file really is, is a collection of cmds that you could run direct from the cli manually. See these links http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
And to implement that, I would guess that you are expected to exercise some file-descriptor gymnastics, possibly involving pipe(), popen(), dup(), dup2(), and other functions that are probably referenced in the 'SEE ALSO' sections of the respective man pages.
--- rod. |
thanks for the links and tips. the book links look good but they appear to need some time, so i will first take a look at the dup() function usage. 'coz i didnt expect this feature to take a lot of time. but i am planning on making a fully functioning shell so even if my project is done am sure to keep going.
by the way, for the record: you guys are alot of help really, this blog isn't just for show. you show lost sheep the way to light. I LIKE THAT :) |
All times are GMT -5. The time now is 02:30 AM. |