系统调用:UNIX、Linux、BSD 和 Solaris 变体

发布于 2024-07-07 22:04:40 字数 60 浏览 8 评论 0原文

主要 *NIX 变体中的系统调用数量是否存在差异?

哪些系统调用将得到普遍支持?

Are there differences between the amount of syscalls in the major *NIX variants ?

Which syscalls would be supported universally ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞别 2024-07-14 22:04:40

任何不是 posix 标准的东西都可能是额外的系统调用,或者可能是系统调用层之上的额外库功能。 如果您的目标是编写可移植代码,请坚持使用 posix,并尽可能使用 c 库(而不是直接系统调用)。

如果您只是好奇,它们的差异很大。 为了兼容 posix,您不需要支持太多系统调用方式。 它指定了您需要支持的接口,但是是否通过调用内核或跳转到共享库来实现这一点很大程度上取决于您。

Mac OS X 甚至不保证版本之间系统调用的二进制兼容性,他们认为它们是系统库和操作系统之间的私有接口。 大多数人认为的系统调用实际上是动态库中调用内核的小存根,如果您直接进行系统调用而不是链接到该动态库并调用存根函数,那么您的代码可能会在操作系统之间中断发布。

这种灵活性意味着许多操作系统实现的系统调用与它们支持 posix 所需的系统调用完全不同,然后处理它们的库中的差异。 例如,Linux 的线程实现基于名为clone() 的系统调用,并且它们处理大量簿记工作以使pthreads 接口在它们的库中工作。

因此,如果您的目标是实现一个不与其他任何内容链接并在多个 UNIX 上运行的标准库,那么在某些情况下您可能会发现事情有点棘手。 如果您的目标是编写一些链接到各种 Unix 上的标准库的东西,您可以获得一个总体统一的接口。

Anything that is not a posix standard may be an additional system call, or it maybe additional library functionality above the system call layer. If your goal is to write portable code stick to posix, and use the c library (as opposed to direct system calls) as much as possible.

If you are just curious, they vary quite widely. You do not need to support much in the way of system calls in order to be posix compliant. It specifies interfaces you need to support, but whether you do that through calling into the kernel or jumping into a shared library is pretty much up to you.

Mac OS X does not even guarantee binary compatibility for system calls between releases, they consider them private interfaces between the system libraries and the OS. What most people consider to be system calls are actually small stubs in a dynamic library that call through to the kernel, and if you make the system calls directly instead of linking to that dynamic library and calling the stub functions then your code may break between OS releases.

That flexibility means a number of OSes implement system calls that are completely different from what they need to support posix, then deal with the differences in their libraries. For example, Linux's threading implementation is based around a system call called clone(), and they deal with much of the bookkeeping to make the pthreads interface work in their libraries.

So if your goal is to implement a standard library the does not link against anything else and works on multiple unixes, you may find things a bit tricky in some cases. If your goal is to write something that links against the standard libraries on various Unixes you can get a generally uniform interface.

拒绝两难 2024-07-14 22:04:40

我能找到的最好的是 Unix-Linux-BSD Cheat-Sheets,针对各种系统调用变体,与 Solaris 系统调用

仅就 Unix 而言,系统调用的数量就增加了四倍,或多或少,具体取决于“系统调用”的含义。
《高级 UNIX 编程》第一版仅关注大约 70 个真正的内核系统调用,例如 open、read 和 write; 但不是 fopen、fread 和 fwrite 等库调用。
第二版包括大约 300 个。(总共大约有 1,100 个标准函数调用,但其中许多是标准 C 库的一部分,或者显然不是内核设施。)
今天的 UNIX 拥有线程、实时信号、异步 I/O 和新的进程间通信功能 (POSIX IPC),而这些在 20 年前都不存在

The best I can find is a Unix-Linux-BSD Cheat-Sheets, for various syscalls variations, to be compared with the Solaris syscalls.

For Unix alone, the number of system calls has quadrupled, more or less, depending on what you mean by "system call."
The first edition of Advanced UNIX Programming focused on only about 70 genuine kernel system calls—for example, open, read, and write; but not library calls like fopen, fread, and fwrite.
The second edition includes about 300. (There are about 1,100 standard function calls in all, but many of those are part of the Standard C Library or are obviously not kernel facilities.)
Today's UNIX has threads, real-time signals, asynchronous I/O, and new interprocess-communication features (POSIX IPC), none of which existed 20 years ago

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文