-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Tail OS #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Tail OS #251
Conversation
This implementation of the tail command in xv6 meets all the requirements specified in the assignment. Custom line counts using the -N option (e.g., tail -5 file.txt) are supported by parsing the -N argument and adjusting the number of lines to display. Invalid or negative values fall back to the default of 10 lines, as expected. When no filename is given, the program reads from standard input (stdin), either manually entered or redirected with <, and prints the last 10 (or N) lines after reaching EOF. Piped input is also supported, such as grep hello file.txt | tail -3, since the implementation reads from file descriptor 0, which works seamlessly with xv6 pipes. The code gracefully handles cases where the input has fewer than N lines by printing all available lines, and it includes basic error handling for invalid files or arguments. The entire file is read into a fixed-size buffer (char buf[4096]), as file sizes in xv6 are limited to 4KB. The implementation uses only standard xv6 system calls (like open, read, write) and follows patterns similar to existing user programs like cat. Overall, this version of tail passes all functional tests and works correctly across files, redirected input, and pipelines. |
Hey, the overall code is well written. Just a few points:
|
Hey, yeah as Tanisha said the code is well written, along with her comments I would like to add mine. Have you tried executing your tail command with files other than README. If yes, then its amazing and if not then try to identify where you should change lines in your files and describe about the change in your comment. Thank you. |
+1 |
This comment was marked as off-topic.
This comment was marked as off-topic.
@tanishachandani Great points, thanks for catching that! |
@Hashmmath Thanks for the suggestion! I initially tested with README, but based on your comment, I ran additional tests with a few different files of varying line lengths. The output matched expectations — the last N lines were displayed correctly in each case. I’ll add a brief note in the PR comments describing the test files and the results to make this clearer. |
No description provided.