Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7787607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:43:33+00:00 2026-06-01T20:43:33+00:00

What is the efficient way to implement tail in *NIX? I came up (wrote)

  • 0

What is the efficient way to implement tail in *NIX?
I came up (wrote) with two simple solution, both using kind of circular buffer to load lines into circular structure (array | doubly linked circular list – for fun).
I’ve seen part of older implementation in busybox and from what I understood, they used fseek to find EOF and then read stuff “backwards”. Is there anything cleaner and faster out there?
I got asked this on interview and asker did not look satisfied. Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:43:34+00:00Added an answer on June 1, 2026 at 8:43 pm

    I don’t think there are solutions different than “keep the latest N lines while reading forward the data” or “start from the end and go backwards until you read the Nth line”.

    The point is that you’d use one or the another based on the context.

    The “go to the end and go backwards” is better when tail accesses a random access file, or when the data is small enough to be put on memory.
    In this case the runtime is minimized, since you scan the data that has to be outputted (so, it’s “optimal”)

    Your solution (keep the N latest lines) is better when tail is fed with a pipeline or when the data is huge.
    In this case, the other solution wastes too much memory, so it is not practical and, in the case the source is slower than tail (which is probable) scanning all the file doesn’t matter that much.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for an efficient way to implement the same kind of layout that
I'm trying to figure out the most efficient way to implement RoR-style partials/collections for
What is the most efficient way for checking for equality of two m *
I'm looking for an efficient way to implement a serialization mechanism in C. I
Efficient way to implement the follwing function in javascript boolean isChild(node1, node2) where, node1
What is an efficient way to implement a singleton design pattern in Java?
Possible Duplicate: Efficient way to implement singleton pattern in Java I was reading this
I'm trying to figure out the most efficient and scalable way to implement a
What is the most efficient way to implement update row if it exists, else
Possible Duplicate: The most efficient way to implement an integer based power function pow(int,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.