Re:Linus vs C++, again
by ramidarigaz on Thursday June 10, 2010 @06:50PM
(#1422042)
I've been meaning to ask this for a very long time: What does the (2) mean? I see (n) in lots of descriptions of calls, but I've never found out what it means.
It refers to sections of the man pages. They are organized like this:
1. General Commands
2. System Calls
3. Subroutines
4. Special Files
5. File Formats
6. Games
7. Macros and Conventions
8. Maintenence Commands
Re:Linus vs C++, again
by ramidarigaz on Friday June 11, 2010 @01:40PM
(#1424065)
Exactly what I wanted to know. Thanks.
and it's used like this:
man 2 write
You got a lot of good answers here, but just so you know: you really only have to remember that open(2) is a syscall and fopen(3) is a library call. That's the important distinction.
The Unix manual is divided into sections (http://en.wikipedia.org/wiki/Man_page#Manual_sections). Section 2 is for system calls. Specifying the section number allows you to disambiguate which section of the manual you want to look in if a man page exists in multiple sections (e.g., "man 1 write" vs. "man 2 write").
Re:Linus vs C++, again
by stonemetal on Thursday June 10, 2010 @07:06PM
(#1422096)
It is where it lives in man. man write returns write(1) an application that sends a message to another user. man 2 write returns write(2) the system call mentioned above(or at least it does on Ubuntu).
It's the "man" section. According to "man man", 2 is the section for system calls. Often you'll have manpages for the same name under different sections, for example sync(1) is a command while sync(2) a system call (which, unsurprisingly, the sync command uses).
Re:Linus vs C++, again
by bretthoerner on Thursday June 10, 2010 @07:05PM
(#1422093)
It's the man page section number. I believe this dates back to when the man(uals) were actually printed out. You'd go to section 2 to find X to disambiguate from a different Y.
Stripping off ambiguity is almost the write syscall handler's only job.
It's worth mentioning here that not only is the convenience vs. explicitness tradeoff different in application code than in bare-metal systems programming code, but that that specific example of convenient app-level API is also an infamous Unix failure. In reality, app code cannot safely assume that an fd is just an abstract bucket you can read, write, close, and seek in.