[Gambas-user] How to tell what invoked this program?

Tobias Boege taboege at ...626...
Sat Jun 27 10:12:01 CEST 2015


On Sat, 27 Jun 2015, adamnt42 at ...626... wrote:
> This is driving me insane!
> 
> How can I tell at runtime if the executable was invoked manually by a user or automatically by a scheduler, e.g. cron, anacron, at etc.
> 
> Can't use the process userid as it may have been invoked as a user cron job.
> I am sure I have done this at least a gazillion times before.... but today????
> 

*Maybe* examine the parent PID and look behind the symlink /proc/<ppid>/exe?
I didn't test it though and I don't know how many names there are for
(ana)cron, at, etc. on different distributions. Another idea would be, if
that's possible, to introduce a command line option to your program and
require the user to set it iff the program is started by such a daemon.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list