I try to understand the seek(2) function from Unix version 6.This example:seek(0,0,2)So the first argument is the file descriptor. And 0 would be the standard input.The second argument is the offset, which is 0.And the third argument tells us according to man page the pointer is set to the size of the file plus offset.But why would you do this? Why would you point after the file?The line is from the source code.
seek function in unix
function
The seek(0, 0, 2) will skip over all data that is buffered up for file descriptor 0.  So after this command, the next read from that filedescriptor will not read anything that was buffered.I think if you examine the code and understand what the actual purpose is, you'll understand that even though file descriptor 0 is normally stdin, this program is really only useful if it is part of a script that is read through that file descriptor.For example, take a look at the following script:gotoecho helloThe goto without any argument is going to trigger the seek.  Without the seek(0, 0, 2) after the goto command exits, the script would still run the echo hello command because the caller of the goto command is simply going to read the next command from the script.