Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I am trying to detect the launch of applications. This may be more pertinent to Kernel Programming, but I am not sure it needs to be implemented in the ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    1

    Detecting the start of applications

    Hi,

    I am trying to detect the launch of applications. This may be more pertinent to Kernel Programming, but I am not sure it needs to be implemented in the kernel!

    What I want to do is detect the launch of an application, and then IF the application is one I care about, then I may trigger some events (debugging, instrumentation, special logging .... ).

    I am not entirely sure of what happens when you 'execute' and application.

    I am guessing here, but I assume when you use the command line to "./myapp", the shell makes a system call to fork() the execution, creating a new process "myapp", and then the parent returns to the command line (if you "&"), or waits for the child to finish. I would have to hook into fork(), does the linux kernel offer any other methods to detect the creation of a new process?

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    You could hook into fork() to see what executes next, but you're going to end up in a lot of incorrect fork()s. The better approach would be to hook into the exec family of system calls, which actually execute programs.

    I don't know the exact approach that you are going to take. One way that I know is to create a .so that overrides the exec family using dlopen and dlsym, and then using LD_PRELOAD to run the library before any program that is executed. But this may or may not be what you want.

    Keep us updated. I'd be interested.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Keep us updated. I'd be interested.
    So would I.

    What will make things a little simpler is that there isn't a whole family of exec system calls; there's just execve. The family of exec library calls are front-ends to this one guy.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...