CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Ping Script - Perl.exe Crashing

 



chazzquire
New User

Jul 17, 2014, 9:21 AM

Post #1 of 4 (579 views)
Ping Script - Perl.exe Crashing Can't Post

Hello,

I am fairly new to Perl, and want to write a script that regularly pings various locations. Ideally I want to script to run on Windows and Linux PCs. I want to script to be able to run indefinitely (days) until a key press.

The script seems to perfectly until Perl.exe crashes without an error message. It doesn't seem to happen after regular amounts of time either - hours or days.

The script and an example config are attached.

Does anyone have any thoughts.. all help is much appreciated!


(This post was edited by chazzquire on Jul 17, 2014, 9:28 AM)
Attachments: config.xml (0.43 KB)
  ping_updated.pl (5.43 KB)


FishMonger
Veteran / Moderator

Jul 17, 2014, 10:10 AM

Post #2 of 4 (570 views)
Re: [chazzquire] Ping Script - Perl.exe Crashing [In reply to] Can't Post

Are you sure perl is crashing? I'd think your script is what is crashing.

Since you specifically stated perl.exe, are you saying that it's crashing on Windows, but not on Linux?

Is that the full script or is it a scaled down version of the actual script you're running?

You've got too much code duplication. You should refactor the script to remove as much of that duplication as possible.

Your logging could be greatly improved if you would use one of the good logging modules on cpan, such as Log::Log4perl.
http://search.cpan.org/~mschilli/Log-Log4perl-1.44/lib/Log/Log4perl.pm


chazzquire
New User

Jul 17, 2014, 11:11 AM

Post #3 of 4 (565 views)
Re: [FishMonger] Ping Script - Perl.exe Crashing [In reply to] Can't Post

Sorry.. yes I agree it's the script thats crashing. What I meant was it crashed with a Perl.exe has stopped working error message (in Windows) rather than a Perl error.

It was a part of a bigger script (with multiple functions being called), but to get to the route cause I've removed everything else.

I understand that my code isn't great.. could you give me an example of something I could refactor?

Thanks.


FishMonger
Veteran / Moderator

Jul 17, 2014, 4:15 PM

Post #4 of 4 (552 views)
Re: [chazzquire] Ping Script - Perl.exe Crashing [In reply to] Can't Post

I don't have time to rewrite your code, but I can give you some suggestions.

Most of the code in each of those 3 subs is exactly the same and only a few lines in each are specific to the given task. Extract that common code and put it into a new sub lets call it test() which will act as a wrapper for those test subs. Instead of calling TCPPingTest() you call the wrapper sub and pass it the type of test to preform and it will call the appropriate test sub.

Making this script platform independent will be problematic if you are using threads. Perl is not thread safe on Windows. Newer versions have better thread support, but they are still problematic. The code you posted isn't making use of threads other than loading the pragmas, but if your running code does, then that could be the cause of the crashes.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives