File::Pid(3pm)
π 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 inFile::Spec->tmpdir()will be created that matches(File::Basename::basename($0))[0] . '.pid'. So, for example, if$0is~/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 π
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
- debian bookworm: libfile-pid-perl 1.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libfile-pid-perl 1.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libfile-pid-perl 1.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfile-pid-perl 1.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfile-pid-perl 1.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms