Author |
Topic: Operating System Concepts queries -HELP (Read 949 times) |
|
puzzlecracker
Senior Riddler
Men have become the tools of their tools
Gender:
Posts: 319
|
|
Operating System Concepts queries -HELP
« on: Nov 23rd, 2004, 3:10pm » |
Quote Modify
|
1) what exactly happend in LINUX OS when script such bash or perl is execute? what are the steps of the compiler and OS? 2) when 'ls' is called, is fork()/exec() are invoked by the system
|
|
IP Logged |
While we are postponing, life speeds by
|
|
|
John_Gaughan
Uberpuzzler
Behold, the power of cheese!
Gender:
Posts: 767
|
|
Re: Operating System Concepts queries -HELP
« Reply #1 on: Nov 23rd, 2004, 8:53pm » |
Quote Modify
|
Is this homework? You know you can always check the source. Linux is great, the kernel is freely available in source code form.
|
|
IP Logged |
x = (0x2B | ~0x2B) x == the_question
|
|
|
puzzlecracker
Senior Riddler
Men have become the tools of their tools
Gender:
Posts: 319
|
|
Re: Operating System Concepts queries -HELP
« Reply #2 on: Nov 23rd, 2004, 9:17pm » |
Quote Modify
|
No, these are interview questions
|
|
IP Logged |
While we are postponing, life speeds by
|
|
|
puzzlecracker
Senior Riddler
Men have become the tools of their tools
Gender:
Posts: 319
|
|
Re: Operating System Concepts queries -HELP
« Reply #3 on: Nov 28th, 2004, 10:33pm » |
Quote Modify
|
If no one really knows these concepts and Linux OS, I will research it myself so that others along with me can get an understanding of these very important and fundamental ideas of CS. just for clarification: does fork()/exec() apply to 'ls' AS WELL AS "cd" command? I am curios about other system calls. and see wether there is a difference among them in terms of implementation. GOod Luck fellowsssssssss............
|
|
IP Logged |
While we are postponing, life speeds by
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 7527
|
|
Re: Operating System Concepts queries -HELP
« Reply #4 on: Nov 29th, 2004, 2:08am » |
Quote Modify
|
For 2) I believe that when the shell interprets 'ls', ls being a program (/usr/bin/ls or so), the shell will fork() a new process and that new process will call exec() to load and execute the /usr/bin/ls program.
|
|
IP Logged |
|
|
|
puzzlecracker
Senior Riddler
Men have become the tools of their tools
Gender:
Posts: 319
|
|
Re: Operating System Concepts queries -HELP
« Reply #5 on: Nov 29th, 2004, 10:13am » |
Quote Modify
|
Hey linux gurus, I looked through the source but couldn't find the actual implementaion of netither ls and cd: http://lxr.linux.no/source/ if anyone is able, please inform me. thx
|
|
IP Logged |
While we are postponing, life speeds by
|
|
|
Aryabhatta
Uberpuzzler
Gender:
Posts: 1321
|
|
Re: Operating System Concepts queries -HELP
« Reply #6 on: Nov 29th, 2004, 10:24am » |
Quote Modify
|
on Nov 29th, 2004, 10:13am, puzzlecracker wrote:Hey linux gurus, I looked through the source but couldn't find the actual implementaion of netither ls and cd: http://lxr.linux.no/source/ if anyone is able, please inform me. thx |
| ls is _not_ a system call. It is an executable. cd is a shell shorthand for the system call chdir. ls is just like any other executable. My guess is you are actually looking for ways to read directories and list them, along with their permissions etc. read the man page about readdir, stat, etc. When you type in a executable name, the shell finds it (usually using the PATH variable) and then forks a new process. The child process then exec's the executable. fork/exec are functions in the stdlib which call the system calls fork and execve. Hope that helps.
|
|
IP Logged |
|
|
|
puzzlecracker
Senior Riddler
Men have become the tools of their tools
Gender:
Posts: 319
|
|
Re: Operating System Concepts queries -HELP
« Reply #7 on: Nov 29th, 2004, 12:26pm » |
Quote Modify
|
That explains: as for the system call? does it also fork and exec to a different process??
|
|
IP Logged |
While we are postponing, life speeds by
|
|
|
Aryabhatta
Uberpuzzler
Gender:
Posts: 1321
|
|
Re: Operating System Concepts queries -HELP
« Reply #8 on: Nov 30th, 2004, 11:07am » |
Quote Modify
|
on Nov 29th, 2004, 12:26pm, puzzlecracker wrote:That explains: as for the system call? does it also fork and exec to a different process?? |
| system calls are executed as part of the same process. For eg, fork is a system call, if we were executing them in a new process, how would we fork (to create the new process) to execute it? Anyway, normally a process is capable of running in 2 (mutually exclusive) modes. The usual user mode and the kernel mode which does the system call execution. Usually there is hardware support which allows the user to trap into (or jump into) the priviledged (kernel) mode (can read/write files etc). For instance in linux on intel x86 machine, system calls are executed by filling the proper registers (which system call and the arguments to the system call) and executing the machine instruction: int 0x80. This causes the the process to go into the kernel mode, where it can do its stuff and then the kernel then returns back to the user mode when the job is done. The user mode is not very priviledged and can mostly read/write memory which is available to it, and execute specific system calls. I would suggest you read a good book on Operating Systems. One such book is "Unix Operating System" by Maurice Bach. Hope that helps.
|
|
IP Logged |
|
|
|
puzzlecracker
Senior Riddler
Men have become the tools of their tools
Gender:
Posts: 319
|
|
Re: Operating System Concepts queries -HELP
« Reply #9 on: Nov 30th, 2004, 3:30pm » |
Quote Modify
|
GREAT, really GREAT help... so clear and elicit now.... Here is the master question though, how do I know, that is can at lest intuively reason, which command involves system call and which involves the processes creation? Is there a guidline that one should follow or simply know as is....................? Thanks again...
|
|
IP Logged |
While we are postponing, life speeds by
|
|
|
Aryabhatta
Uberpuzzler
Gender:
Posts: 1321
|
|
Re: Operating System Concepts queries -HELP
« Reply #10 on: Nov 30th, 2004, 5:18pm » |
Quote Modify
|
on Nov 30th, 2004, 3:30pm, puzzlecracker wrote: Here is the master question though, how do I know, that is can at lest intuively reason, which command involves system call and which involves the processes creation? Is there a guidline that one should follow or simply know as is....................? |
| What do you mean by 'command'? Are you talking about commands to the shell, say like bash? You might want to read what shell builtins are there and how they translate (if at all they translate) to system calls. Eg: cd translates directly to chdir, but 'if' or 'for' do not need system calls. Shell redirection (using > file) uses system calls open and dup/dup2. Running executables (like ls) will involve the system call exec and fork (in most cases). So if you do something like ls > file, the systems calls could be fork, exec, open and dup and close (and probably other system calls). It would help if you had a knowledge of what system calls are available. A way to judge what is happening is: what would _you_ have done to provide that feature in a shell which you would write (you would need to know what system calls are available for that though). If you just want to know if a new process has been created, you could just use 'ps' (from say a different shell) to look at the list of processes and try to figure out., but it is usually when an executable is executed by the shell (for instance when you type in ps, which is actually the executable /bin/ps or something similar), that a new process is created. To get started you could read some faqs available on the net. I think one was called unix.programmer.faq, sorry don't remember clearly. Or maybe you could read some book about systems programming... Hope that helps.
|
|
IP Logged |
|
|
|
TenaliRaman
Uberpuzzler
I am no special. I am only passionately curious.
Gender:
Posts: 1001
|
|
Re: Operating System Concepts queries -HELP
« Reply #11 on: Dec 1st, 2004, 9:35pm » |
Quote Modify
|
check here for a "blunt" list of system calls, http://www.sju.edu/~jhodgson/systems/sys_call.html U can man them to find more abt them.
|
|
IP Logged |
Self discovery comes when a man measures himself against an obstacle - Antoine de Saint Exupery
|
|
|
John_Gaughan
Uberpuzzler
Behold, the power of cheese!
Gender:
Posts: 767
|
|
Re: Operating System Concepts queries -HELP
« Reply #12 on: Dec 7th, 2004, 11:00am » |
Quote Modify
|
Try looking in the /bin directory. There you will find your utilities such as ls, rm, and cd. They are part of (I think) the GNU core utilities package.
|
|
IP Logged |
x = (0x2B | ~0x2B) x == the_question
|
|
|
igni_ferroque
Newbie
Posts: 11
|
|
Re: Operating System Concepts queries -HELP
« Reply #13 on: Dec 7th, 2004, 8:27pm » |
Quote Modify
|
Quote:1) what exactly happend in LINUX OS when script such bash or perl is execute? what are the steps of the compiler and OS? |
| The operating system recognizes the two-byte magic cookie '#!' (also called the she-bang!) and executes the program (interpreter) specified by the string following the she-bang. The path of the script file appears as the second argument passed to the interpreter (argv[1]), followed by any arguments passed to the script file.
|
|
IP Logged |
|
|
|
|