I wrote a simple daemon.
This daemon should respond when I run any program.
How to do this?
In a big daemon loop:
while(1)
{
/* function which catches new programm running */
}
What functions to call in linux, when i’m running a new program (create new process)?
I don’t know if there exists a better way, but you could periodically scan the
/procfilesystem.For example,
/proc/<pid>/exeis a symlink to the process’s executable.On my systems (Ubuntu/RedHat),
/proc/loadavgcontains the number of running processes (the number after the forward slash) as well as the pid of the most recently started process. If your daemon polls the file, any change to either of the two numbers will tell it when it needs to re-scan/proclooking for new processes.This is by no means bullet-proof, but is the most suitable mechanism I can think of.