0

I have a Python script which uses os.system() to call certain commands an Linux machine.

These commands might be standard commands such as ls, grep etc., or some custom commands present on that machine.

I want to trace what syscalls get called by these commands, but within the Python script itself. So, once I do:

os.system(command) 

I want to return a list of all system calls made by that particular command.

So that I can iterate over the list and filter for any syscalls I need to investigate. Ideally, what I am planning to do is create a dictionary which will help me map the parameters that I gave to my command above, and what went in to the syscall eventually.

Is there a nice Pythonic way to do this?

3
  • do you have the ability to change this code from calling os.system(...) to, say, self.system(...)? If so, write a wrapper that logs each call before making the actual call. Commented Nov 23, 2015 at 4:08
  • I was about to suggest os.system('strace ' + command) and parse the output but from @ColinSchoen's answer it looks like p-trace is a better way. Commented Nov 23, 2015 at 5:26
  • yes. Got this. but how do i use the ptrace library in my python module and not just from command line ? Can you please give an example ? Commented Nov 24, 2015 at 5:54

1 Answer 1

1

Have a look at python p-trace

http://python-ptrace.readthedocs.org/en/latest/syscall.html

Sign up to request clarification or add additional context in comments.

1 Comment

Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.