Can I Set Process Name?

Daniel Bye dan at slightlystrange.org
Tue Jul 8 09:00:37 PDT 2003


On Tue, Jul 08, 2003 at 08:43:12AM -0700, Drew Tomlinson wrote:
> ----- Original Message ----- 
> From: "Daniel Bye" <dan at slightlystrange.org>
> To: "FreeBSD Questions" <freebsd-questions at freebsd.org>
> Sent: Tuesday, July 08, 2003 8:29 AM
> 
> On Tue, Jul 08, 2003 at 08:26:45AM -0700, Drew Tomlinson wrote:
> > >
> > > $0='webmin';
>              ^
> > >
> > > However when starting the program it dies with the following
> message:
> > >
> > > Is there something really easy I'm missing?  If it's complicated I'm
> > > going to forget it as it's not that important.
> 
> > Yes - a `;' at the end of the line  ;-)
> 
> Thanks.  That removed the error but failed to change the process name.
> I looked at the code a little more.  I'm not experienced in this but it
> seems to me that the 'package miniserv;' line calls a precompiled
> program?  Here's the beginning of the script:

No - in Perl, a "package" is a namespace - an abstract storage space.  It
helps keep a module's (i.e. package's) variables etc logically separate from
those of other packages.  It prevents collisions in variable names, data
structures, etc.

The variable $0 contains, by default, the name of the file containing the
currently running script.  

> 
> #!/usr/bin/perl
> # A very simple perl web server used by Webmin
> 
> $0='webmin';
> 
> # Require basic libraries
> package miniserv;    <-- This is just declaring that the following code is
                           in the "miniserv" package.
> use Socket;
> use POSIX;
> 
> Then a little farther in the script, I see this code:
> 
> # Get miniserv's perl path and location
> $miniserv_path = $0;    
> open(SOURCE, $miniserv_path);
> <SOURCE> =~ /^#!(\S+)/; $perl_path = $1;
> close(SOURCE);
> @miniserv_argv = @ARGV;
> 
> So I suspect the process name gets set in this somewhere?

As you have poked $0 before it gets this far, no - $0 contains the value you
set above.  Which might, in itself, cause problems later in the script.
Without reviewing it, I couldn't tell you.

Dan

-- 
Daniel Bye

PGP Key: ftp://ftp.slightlystrange.org/pgpkey/dan.asc
PGP Key fingerprint: 3B9D 8BBB EB03 BA83 5DB4 3B88 86FC F03A 90A1 BE8F
                                                                     _
                                              ASCII ribbon campaign ( )
                                         - against HTML, vCards and  X
                                - proprietary attachments in e-mail / \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20030708/480da340/attachment.bin


More information about the freebsd-questions mailing list