in reply to Re: Mechanism for ensuring only one instance of a Perl script can only run?
in thread Mechanism for ensuring only one instance of a Perl script can only run?
my $processes = Proc::ProcessTable->new; for ( @{ $processes->table } ) { …; }
I don't think that will always work safely:
Trying to locking the executable should be free of race conditions (or else flock() would be severely broken) and should also work with soft and hard links, as the file is locked, not one of its directory entries.
Quick assign to $0 demo:
/root>perl -E 'say `cat /proc/$$/cmdline`' perl-Esay `cat /proc/$$/cmdline` /root>perl -E '$0="find me"; say `cat /proc/$$/cmdline`' find me /root>
pstree on a host with about 10 containers (running Proxmox VE, both host and containers using Debian 11)
systemd─┬─agetty ├─cron ├─dbus-daemon ├─dovecot─┬─anvil │ ├─config │ └─log ├─8*[dtach───lxc-console] ├─2*[iscsid] ├─lxc-monitord ├─lxc-start───systemd─┬─3*[agetty] │ ├─cron │ ├─dbus-daemon │ ├─dhclient───3*[{dhclient}] │ ├─es-ct18-linux-a │ ├─nullmailer-send │ ├─perl │ ├─rsyslogd───2*[{rsyslogd}] │ ├─systemd-journal │ ├─systemd-logind │ ├─systemd-network │ └─systemd-resolve ├─lxc-start───systemd─┬─3*[agetty] │ ├─apache2───10*[apache2] │ ├─cron │ ├─dbus-daemon │ ├─dhclient───3*[{dhclient}] │ ├─nullmailer-send │ ├─rsyslogd───2*[{rsyslogd}] │ ├─systemd-journal │ ├─systemd-logind │ ├─systemd-network │ └─systemd-resolve ├─lxc-start───systemd─┬─3*[agetty] │ ├─cron │ ├─dbus-daemon │ ├─dhclient───3*[{dhclient}] │ ├─mini_httpd │ ├─nullmailer-send │ ├─rsyslogd───2*[{rsyslogd}] │ ├─systemd-journal │ ├─systemd-logind │ ├─systemd-network │ └─systemd-resolve ├─lxc-start───systemd─┬─3*[agetty] │ ├─cron │ ├─dbus-daemon │ ├─dhclient───3*[{dhclient}] │ ├─dovecot─┬─anvil │ │ ├─auth │ │ ├─config │ │ ├─imap │ │ ├─log │ │ └─stats │ ├─exim4 │ ├─multi-fetchmail───8*[fetchmail] │ ├─rsyslogd───2*[{rsyslogd}] │ ├─systemd-journal │ ├─systemd-logind │ ├─systemd-network │ └─systemd-resolve ├─lxc-start───systemd─┬─3*[agetty] │ ├─cron │ ├─dbus-daemon │ ├─mini_httpd │ ├─nullmailer-send │ ├─rsyslogd───2*[{rsyslogd}] │ ├─systemd-journal │ ├─systemd-logind │ ├─systemd-network │ ├─systemd-resolve │ └─urbackupsrv───20*[{urbackupsrv}] ├─lxc-start───systemd─┬─3*[agetty] │ ├─apache2───5*[apache2] │ ├─cron │ ├─dbus-daemon │ ├─dhclient───3*[{dhclient}] │ ├─nullmailer-send │ ├─postgres───6*[postgres] │ ├─rsyslogd───2*[{rsyslogd}] │ ├─systemd-journal │ ├─systemd-logind │ ├─systemd-network │ └─systemd-resolve ├─lxc-start───systemd─┬─3*[agetty] │ ├─cron │ ├─dbus-daemon │ ├─dhclient───3*[{dhclient}] │ ├─lighttpd │ ├─nullmailer-send │ ├─rsyslogd───2*[{rsyslogd}] │ ├─systemd-journal │ ├─systemd-logind │ ├─systemd-network │ └─systemd-resolve ├─lxc-start───systemd─┬─3*[agetty] │ ├─cron │ ├─dbus-daemon │ ├─mini_httpd │ ├─nullmailer-send │ ├─rsyslogd───2*[{rsyslogd}] │ ├─systemd-journal │ ├─systemd-logind │ ├─systemd-network │ └─systemd-resolve ├─lxc-start───systemd─┬─3*[agetty] │ ├─apache2───2*[apache2───26*[{apache2}]] │ ├─cron │ ├─dbus-daemon │ ├─mini_httpd │ ├─nullmailer-send │ ├─rsyslogd───2*[{rsyslogd}] │ ├─systemd-journal │ ├─systemd-logind │ ├─systemd-network │ └─systemd-resolve ├─lxc-start───systemd─┬─3*[agetty] │ ├─cron │ ├─dbus-daemon │ ├─lighttpd │ ├─nmbd │ ├─nullmailer-send │ ├─rsyslogd───2*[{rsyslogd}] │ ├─smbd─┬─cleanupd │ │ ├─lpqd │ │ ├─smbd │ │ └─smbd-notifyd │ ├─systemd-journal │ ├─systemd-logind │ ├─systemd-network │ ├─systemd-resolve │ └─vsftpd ├─lxcfs───6*[{lxcfs}] ├─mdadm ├─mini_httpd ├─nullmailer-send ├─pmxcfs───12*[{pmxcfs}] ├─pve-firewall ├─pve-ha-crm ├─pve-ha-lrm ├─pve-lxc-syscall───2*[{pve-lxc-syscall}] ├─pvedaemon───3*[pvedaemon worke] ├─pvefw-logger───{pvefw-logger} ├─pveproxy───3*[pveproxy worker] ├─pvescheduler ├─pvestatd ├─qmeventd ├─rpcbind ├─rrdcached───12*[{rrdcached}] ├─rsyslogd───3*[{rsyslogd}] ├─smartd ├─spiceproxy───spiceproxy work ├─sshd───sshd───sshd───bash───sudo───bash───pstree ├─systemd───(sd-pam) ├─systemd-journal ├─systemd-logind ├─systemd-timesyn───{systemd-timesyn} ├─systemd-udevd ├─watchdog-mux └─zed───2*[{zed}]
Every lxc-start is a parent process of a container, every systemd that is a child of a lxc-start is the init process (pid 1) of a container, each of those systemds and all of their children are running in a container.
Alexander
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Mechanism for ensuring only one instance of a Perl script can only run?
by karlgoethebier (Abbot) on Dec 03, 2022 at 09:26 UTC | |
Re^3: Mechanism for ensuring only one instance of a Perl script can only run?
by parv (Parson) on Dec 03, 2022 at 07:50 UTC |