Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am running a program in unix platform.\n I want to display the process id of the program currently running. Is there any function available for this?. Reason for this is , this program produces txt file as output , this will be used simaltaneously by users. I want the filename to be distinct. Thanks in Adv,

Replies are listed 'Best First'.
Re: Find the PID of current program
by madbombX (Hermit) on Nov 28, 2006 at 12:37 UTC
    This is the section right out of the Perl documentation for $$. You can find it in perlvar.
    $PROCESS_ID $PID $$ The process number of the Perl running this script. Yo +u should consider this variable read-only, although it will be a +ltered across fork() calls. (Mnemonic: same as shells.) Note for Linux users: on Linux, the C functions "getpid +()" and "getppid()" return different values from different thre +ads. In order to be portable, this behavior is not reflected by + $$, whose value remains consistent across threads. If you w +ant to call the underlying "getpid()", you may use the CPAN mo +dule "Linux::Pid".
Re: Find the PID of current program
by Callum (Chaplain) on Nov 28, 2006 at 12:09 UTC
    $$
Re: Find the PID of current program
by Fengor (Pilgrim) on Nov 28, 2006 at 12:48 UTC
    for a list of perl variables i'll recommend this excellent node: Perl Special Variables Quick Reference

    --
    "WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
    -- Terry Pratchett, "Reaper Man"

Re: Find the PID of current program
by smokemachine (Hermit) on Nov 28, 2006 at 12:09 UTC
    $$
Re: Find the PID of current program
by andyford (Curate) on Nov 28, 2006 at 15:48 UTC
Re: Find the PID of current program
by andreas1234567 (Vicar) on Nov 30, 2006 at 06:44 UTC
    Have a look at Log::Log4perl. It provides the PID functionality you want, besides being a powerful log framework: Writes both to screen (STDOUT) and a file named pid.pid.log that is rotated on 50K: Andreas
    --