调用系统调用的不同方法

时间:2014-10-30 09:36:51

标签: linux linux-kernel system system-calls

我发现系统调用“stat”与调用

的行为不同
stat()

syscall(__NR_stat) 

我不明白为什么同样的系统调用只是表现不同 因为打电话的方式有变化吗?

2 个答案:

答案 0 :(得分:1)

今天Linux上的C库提供的stat()通常是在内核的sys_stat64()之上实现的。

这是man page应该是您的第一个参考的众多案例之一:

  Underlying kernel interface

   Over time, increases in the size of the stat structure have led to
   three successive versions of stat(): sys_stat() (slot __NR_oldstat),
   sys_newstat() (slot __NR_stat), and sys_stat64() (new in kernel 2.4;
   slot __NR_stat64).  The glibc stat() wrapper function hides these
   details from applications, invoking the most recent version of the
   system call provided by the kernel, and repacking the returned
   information if required for old binaries.  Similar remarks apply for
   fstat() and lstat().

您可能还想获取已安装的C库的源包,并查看它以了解包装器的实际实现。

答案 1 :(得分:0)

如果是C代码,那么你应该意识到,你有一些语法错误。 但无论如何,在平台上可能有不同的__NR_stat marcro值。要找到这个,你必须看到/usr/include/unistd.h文件。谁知道调用这些函数的顺序是什么? 请给我们更多信息。