Why such a hack? This is a solved problem already. Try Linux audit API. You can set it up for tracking various actions, and you'll get a log with all the information including a process name.
https://linux-audit.com/configuring-and-auditing-linux-syste...