- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl script help
Operating System - HP-UX
1822480
Members
2523
Online
109642
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2004 04:03 AM
тАО04-23-2004 04:03 AM
Please help me.
I need a secure way using Perl to check
whether the another example of main program is in the memory like process.
If another example is running,then not to start the program, else - to start.
But without using system("ps -ef | grep myprogram").
I need a clearly Perl-example.
Thanks for help.
liana
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2004 04:12 AM
тАО04-23-2004 04:12 AM
Solution
Probably the most straightforward method is as your script starts, check for the existence of a file; e.g. /var/tmp/mygrogram.pid
If the file does not exist, then it is safe to continue. You create the file and write the PID of your current process into the file. Upon exit, remove the file.
If the file does exist, read the contents of the file to get the PID of the process that wrote it.
send a kill 0 to this process.
$rslt = kill 0,$other_pid;
if ($rslt)
{
exit(0); # currently running process
}
else
{ # process dead even though file exists
# unlink the original file
# create new PID file and write current PID
# do your thing
#
# remove PID file
exit($status);
}
I would also add signal handlers to remove this file.
If the file does not exist, then it is safe to continue. You create the file and write the PID of your current process into the file. Upon exit, remove the file.
If the file does exist, read the contents of the file to get the PID of the process that wrote it.
send a kill 0 to this process.
$rslt = kill 0,$other_pid;
if ($rslt)
{
exit(0); # currently running process
}
else
{ # process dead even though file exists
# unlink the original file
# create new PID file and write current PID
# do your thing
#
# remove PID file
exit($status);
}
I would also add signal handlers to remove this file.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2004 06:54 AM
тАО04-23-2004 06:54 AM
Re: Perl script help
since there is NO WAY to return to the script after an exit, I do not understand why people write
if (expression) {
exit $status;
}
else {
some other code ...
}
this is IMHO cargo cult programming and only blurs the script. Just like
cat file | process
is unneccesarily taking system resources where
process < file
would do just as good.
expression and exit $status;
and go on with the real work
Clay, I realy enjoy your good answers, they are mostly short clear and to the point, but I just couldn't let this one go. sorry.
BTW I think that CPAN offers a nice bunch of Unix interaction moduls and functions on ftp://download.xs4all.nl/pub/mirror/CPAN/modules/by-module/Proc/ (Proc::ProcessTable is included in my builds), and there is even a complete HP-UX namespace: ftp://download.xs4all.nl/pub/mirror/CPAN/modules/by-module/HPUX/
Enjoy, Have FUN! H.Merijn
if (expression) {
exit $status;
}
else {
some other code ...
}
this is IMHO cargo cult programming and only blurs the script. Just like
cat file | process
is unneccesarily taking system resources where
process < file
would do just as good.
expression and exit $status;
and go on with the real work
Clay, I realy enjoy your good answers, they are mostly short clear and to the point, but I just couldn't let this one go. sorry.
BTW I think that CPAN offers a nice bunch of Unix interaction moduls and functions on ftp://download.xs4all.nl/pub/mirror/CPAN/modules/by-module/Proc/ (Proc::ProcessTable is included in my builds), and there is even a complete HP-UX namespace: ftp://download.xs4all.nl/pub/mirror/CPAN/modules/by-module/HPUX/
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP