Digimon Digitizer 2 Digimon Digitizer 2 - 6 months ago 8
Perl Question

How to know whether my program is being execute manually or by cron or from another script

My question is stated in the title:


How can I discover whether my program is being execute manually or by cron or from another script, and what account is being used?


I hope you guys can help me.

Answer

You can get the parent PID with getppid.

Then finding the parent process name from its PID is non-portable. On linux/unix you could run the ps command and parse the output. On Windows you'll probably need something like Win32::Process::List. No idea for OSX or other operating systems, try Googling perl get process name from pid.

Comments