File::Pid(3pm)

πŸ“¦
version 1.01 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– File::Pid β€” pid file manipulation, but make it make sense πŸ’–

okay bestie, so this is File::Pid, a lil Perl module from the User Contributed Perl Documentation collection, and it's here to handle all your pid file drama so you don't have to. no cap. ✨


✨ NAME ✨

File::Pid β€” Pid File Manipulation πŸ’…


🌸 SYNOPSIS 🌸

like, here's the whole vibe in one go:

use File::Pid;

my $pidfile = File::Pid->new({
  file => '/some/file.pid',
});

$pidfile->write;

if ( my $num = $pidfile->running ) {
    die "Already running: $num\n";
}

$pidfile->remove;

see? iconic. write it, check it, yeet it. πŸ¦‹


πŸŽ€ DESCRIPTION πŸŽ€

This software manages a pid file for you. That's the whole job. It will:

  • create a pid file 🫢
  • query the process inside it to discover if it's still running πŸ”
  • remove the pid file πŸ—‘οΈ

main character energy tbh.

🌟 new

my $pidfile = File::Pid->new;

my $thisfile = File::Pid->new({
  file => '/var/run/daemon.pid',
});

my $thisfileandpid = File::Pid->new({
  file => '/var/run/daemon.pid',
  pid  => '145',
});

This constructor takes two optional parameters. yes, optional. it's flexible like that. πŸ’β™€οΈ

  • "file" β€” the name of the pid file to work on. If you don't specify it, a pid file located in File::Spec->tmpdir() will be created that matches (File::Basename::basename($0))[0] . '.pid'. So, for example, if $0 is ~/bin/sig.pl, the pid file will be /tmp/sig.pl.pid. it just knows what to call itself, periodt. 🌈
  • "pid" β€” the pid to write to a new pidfile. If not specified, $$ is used when the pid file doesn't exist. When the pid file does exist, the pid inside it is used. lowkey smart. 🧠

πŸ’œ file

my $pidfile = $pidfile->file;

Accessor/mutator for the filename used as the pid file. get it, set it, slay. πŸ’…

πŸ’œ pid

my $pid = $pidfile->pid;

Accessor/mutator for the pid being saved to the pid file. πŸ“

πŸ”₯ write

my $pid = $pidfile->write;

Writes the pid file to disk, inserting the pid inside the file. On success, the pid written is returned. On failure, undef is returned. so like, check your return value bestie, don't just assume. 😭

πŸ”₯ running

my $pid = $pidfile->running;
die "Service already running: $pid\n" if $pid;

Checks to see if the pricess identified in the pid file is still running. (yes, "pricess", that's what the original says, we keep the lore fr fr πŸ’€)

If the process is still running, the pid is returned. Otherwise undef is returned. so a truthy return = it's alive, falsy = it's gone. vibe check complete. ✨

πŸ”₯ remove

$pidfile->remove or warn "Couldn't unlink pid file\n";

Removes the pid file from disk. Returns true on success, false on failure. that's it, that's the method. πŸ—‘οΈ

🧚 program_name

This is a utility method that allows you to determine what File::Pid thinks the program name is. Internally this is used when no pid file is specified. it's giving "who even am i" but make it useful. πŸ‘‘


🌈 SEE ALSO 🌈

  • perl.

πŸ‘‘ AUTHOR πŸ‘‘

Casey West, <casey@geeknest.com>.


Copyright (c) 2005 Casey West.  All rights reserved.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

k that's the whole page bestie, go write some pid files responsibly 🫢

and for the cute sign-off: this gorgeous lil doc shipped with perl v5.34.0 and was dated 2022-06-13. historic. iconic. ate. πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from