Skip to content
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

Log process exit time #214

Closed
serkan-ozal opened this issue Apr 18, 2022 · 4 comments
Closed

Log process exit time #214

serkan-ozal opened this issue Apr 18, 2022 · 4 comments

Comments

@serkan-ozal
Copy link

Hi,

Not sure whether this is possible technically but it would be helpful if somehow snoopy could log process exit times to trace the process execution times.

@bostjan
Copy link
Member

bostjan commented Apr 19, 2022

Hey @serkan-ozal,

What's the actual use case that you'd want to solve with such a feature? Personally, I've never needed such information from Snoopy, because I was able to tell, from the command itself, for how long it has been running - it's either in the order or seconds, or days/weeks. In the past, for the stuff that I needed the execution time (it was a PHP application), I've built those measurements into the PHP itself.

Technicalities

First of all, Snoopy's current approach to operation is kinda hands-off:

  • It gets preloaded into the program's memory.
  • It simply intercepts calls to exec()/execve(),
  • It logs what's about to be executed,
  • Then it continues with the actual execv()/execve() call.
    At that point, Snoopy is out of the picture again and doing nothing until execv()/execve() is (potentially) called again. Snoopy also keeps no state information.

Also, in the child process, up to this point, Snoopy does nothing:

  • It it simply preloaded by the dynamic loader.
  • And then it waits for the first execv()/execve() call.
    Meanwhile the child process is doing whatever it is doing.

Technically (to some extent, according to my quick googling) what you're asking for may be doable with:

Please describe your use case and let's then discuss further.

PS: Have you checked alternative solutions for this, things like Linux' implementation of BSD process accounting, Linux's auditd subsystem or maybe even a BPF?

@serkan-ozal
Copy link
Author

Hi @bostjan,

The use case is that we want to trace processes with their

  • name,
  • start time,
  • end time (or duration),
  • args,
  • exit code

In addition to snoopy, we have also considered using process accounting, auditd and BPF. However, as far as we experiment, currently only BPF based https://github.com/iovisor/bcc/blob/master/tools/exitsnoop.py does what we want to be able to get process exit time with its exit code.

@bostjan
Copy link
Member

bostjan commented Apr 19, 2022

Haha, @serkan-ozal, I had more the "why, to what purpose?" question in mind, no the details of what you'd want to be collected to fulfil said purpose. :) (BTW feel free to not share this information, I understand it might be considered private.)

That said, and given how Snoopy currently (and since forever) operates, I don't think this feature is a good fit for Snoopy's current internal architecture. Refactoring from ld.so.preload-based(-only) operation to BPF (for triggers) + daemon (for trigger consumption + log event creation) is no small feat, and it's probably simpler to just create a new tool, something similar to exitsnoop you found.

@serkan-ozal
Copy link
Author

Ok, thanks for the info 👍 For now, BPF based solution seems the best way for us to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants