in reply to Re^2: custom name to the process
in thread custom name to the process

I've used a symlinking approach allowing the real script to see how it was called, using a dispatch table.. perhaps this will work for your purposes:

Create a script for example /usr/sbin/myscript.pl
#!/usr/bin/perl use strict; use warnings; my $ME = $0 ; $ME =~ s@^\.\/|\/.*\/@@g; $ME =~ /myscript.pl/ and die ("\n Please dont call me directly!\n\n"); my %workerscripts = ( 'worker01' => \&worker01, 'worker02' => \&worker02, 'worker03' => \&worker03 ); my $real_command = $workerscripts{&findME}; &$real_command; #--- sub findME { while ( my($k,$v) = each %workerscripts ) { return $k if $k =~ /$ME/ ; }; }; sub worker01 { print "worker01 was called\n"; exit 0; }; sub worker02 { print "worker02 was called\n"; exit 0; }; sub worker03 { print "worker03 was called\n"; exit 0; };


Then create links to that script:
cd /usr/bin/ ln -s /usr/sbin/myscript.pl worker01 ln -s /usr/sbin/myscript.pl worker02 ln -s /usr/sbin/myscript.pl worker03
Invoke /usr/bin/worker01, worker02, or worker03 and the proper subroutine should be called..

Does that get you closer?
-Harold

Replies are listed 'Best First'.
Re^4: custom name to the process
by cdarke (Prior) on Dec 05, 2007 at 10:44 UTC
    Using this principle you could create the symlinks from Perl, using symlink. That way you can launch the script using fork and exec, and delete (unlink) the symlink in the parent.

    Be careful not to delete the symlink before the child has had chance to exec the symlink. Either waitpid the parent before deleteing it, or use some IPC to indicate the child has started.
Re^4: custom name to the process
by rimvydazas (Novice) on Dec 06, 2007 at 18:22 UTC
    I like this approach. I am going try this one. Thanks Harold! Thanks to all other people helping me out!