如何区分呼叫AC库功能与进行系统调用?
有c库函数 pipe(3) 和kernel(系统呼叫)< a href =“ https://linux.die.net/man/2/pipe” rel =“ nofollow noreferrer”> pipe(2)。 两者都具有相同的签名,应该像这样使用(包括标头):
#include <unistd.h>
int fds[2];
pipe(fds);
此代码调用管道(3)或管道(2)会吗? 我如何决定要使用LIBC还是系统调用? 如果管道(3)和管道(2)相同,我怎么知道?
There is the C library function pipe(3) and the kernel (system call) pipe(2).
Both have the same signature and should be used like this (same include header):
#include <unistd.h>
int fds[2];
pipe(fds);
Will this code call pipe(3) or pipe(2)?
How can I decide whether I want to use libc or a system call?
If pipe(3) and pipe(2) are the same, how do I know that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它将调用
管道(3)
。可以直接调用
c
直接调用syscall(2)
将正确的参数“插入”正确的寄存器中,或__ ASM __
做同样的事情。It will call
pipe(3)
.There is no way to call the system call directly from
C
, you eithersyscall(2)
to "stuff" the right arguments into the right registers before executing architecture-appropriate system call instruction, or__asm__
to do the same.我认为您在没有一个的地方做出了区别。您的代码将调用
管道
库功能,这只是PIPE
系统调用围绕的包装器。这不是一个/或。第3节手册页来自POSIX程序员的手册,第2节手册页面是Linux特定的。I think you're making a distinction where there isn't one. Your code will call the
pipe
library function, which is just a wrapper around thepipe
system call. It's not an either/or. The section 3 manual page is from the POSIX programmer's manual, and the section 2 manual page is Linux-specific.