---------- Forwarded message ----------
From:
Betty O'Neil <eon...@cs.umb.edu>
Date: Wed, Feb 10, 2010 at 2:44 PM
Subject: Re: Questions on syscall...
To: Truong Than <
4tr...@gmail.com>
OK to forward this to the google group?
On Wed, 10 Feb 2010, Truong Than wrote:
Hi Professor.
As we covered the syscalls last class, I have couple of questions on the
topic:
1. Are the syscalls (open, read, write, close, fork, ...) provided by an OS
in terms of internal commands or external commands ?
I'm not sure where these terms internal commands, external commands come from. In UNIX, the C library has a certain API specified in man pages
which includes the system calls. The system calls execute via a
special machine instruction, such as ta on Sparc.
2. If they are external commands, are they loaded when the system starts or
at the runtime?
They exist as soon as the bootup of the OS completes. They are used by
process 1, for example, the first process created by fork.
3. What kind of files are they? executable, DLL, or something else?
They are not files, except in the sense that the OS itself is stored
in the kernel file before it is booted up.
*** 4. In C, when calling to them directly (i.e. not via C library), what
happens, step by step? How does C compiler get these syscall, where does it
look at to find these syscalls, and can we call to these syscalls on the
shell?
To call a syscall directly, you need to use assembly. Then you mimic
the instructions you saw in the C library disassembly, loading certain
registers,then doing the syscall instruction.
The C compiler doesn't itself know about syscalls. It sees some C code
like write(1,...), and issues the same calling code as it would for
any C function. It doesn't need to know where write is implemented.
It issues a relocatable object file with an external undefined symbol
for write. The loader sees that symbol, and matches it with the
C library defined symbol for write, allowing an executable file
to be written.
No, the shell can only run executable, etc. It doesn't have the
full power of a C program, so you have to write a C program (say)
compile it into an executable, and run the executable from the shell.
The 4th question is the most important one that helps me to clear out
vagueness and misunderstanding that I may have.
Thank you very much.
Truong.