Re: Win32 - Killing Processes
On Tue, Apr 9, 2013 at 11:15 PM, Mike Flannigan mikef...@att.net wrote: On 4/9/2013 6:10 AM, Jonathan Harris wrote: Hi All I am using Strawberry Perl (latest release) on a Windows 2003 SP2 server I am trying to use a script to look at running processes, look for a specific process, and kill that process if it is alive for more than 4 minutes as this would mean that the process has hung When testing killing Notepad or Firefox, it works fine In practice when trying to kill ovntag or oprop processes, it doesn't It uses the following to kill the process: Win32::Process::KillProcess ($pid, \$exitcode); So here's the question. Is there a difference between killing a process that is alive and one that has hung? In theory a process is a process, right?! But the hanging process does not die! Is there a better way to kill a process so that a hanging process will actually die? Thanks in advance Jon It's highly unlikely this will fix your problem, but I will throw it out for consideration: $ProcessObj-Kill( $exitcode ) Kill the associated process, have it terminate with exit code $ExitCode Mike -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ Hi Mike Many thanks for your response I updated this post yesterday with a revised subject (Win32 - Killing Processes - Update Possible Solution ) - probably should have kept it all on the same thread! I did try what you suggested, but with not much luck Instead as an option I am testing a fix, using a system call to Windows to force quit the process system 'taskkill /f /PID ' . ($new_pid); As anyone who has used windows has probably experienced before, when trying to use task manager to quit a hung process, the 'end process' button doesn't always do the job first time around and can often require multiple clicks! I have the feeling that this process gets itself into that state, so a single call from the Win32 module is probably insufficient However, using taskkill on the cli with the 'force' argument has a far higher success rate - hence the system call Hopefully this will solve the issue! If you can think of anything else at all, I'm all ears and grateful for any input! Thanks again Jon
Any alternative for substr() function
Hi All, I want to extract certain char sets (e.g. char 4 to 9, char 11 to 14 etc.) from each line of my file and store them in separate variables for further processing. My file size can vary from thousand to millions of lines. If I use perl in-built function substr() to data extraction, it has huge impact on performance. Is there any alternative for this? Thanks in advance. Cheers, Kavita
Re: Any alternative for substr() function
Hi Kavita, You may try unpack (http://perldoc.perl.org/functions/unpack.html) Also read these: http://www.perlmonks.org/?node_id=308607, http://stackoverflow.com/questions/1083269/is-perls-unpack-ever-faster-than-substr On Wed, Apr 10, 2013 at 3:46 PM, kavita kulkarni kavitahkulka...@gmail.comwrote: Hi All, I want to extract certain char sets (e.g. char 4 to 9, char 11 to 14 etc.) from each line of my file and store them in separate variables for further processing. My file size can vary from thousand to millions of lines. If I use perl in-built function substr() to data extraction, it has huge impact on performance. Is there any alternative for this? Thanks in advance. Cheers, Kavita -- Regards, Chankey Pathak http://www.linuxstall.com
Re: Any alternative for substr() function
Hi, On 10 Apr 2013 11:30, Chankey Pathak chankey...@gmail.com wrote: Hi Kavita, You may try unpack (http://perldoc.perl.org/functions/unpack.html) unpack would not work if the OP has varying length of lines. Also read these: http://www.perlmonks.org/?node_id=308607, http://stackoverflow.com/questions/1083269/is-perls-unpack-ever-faster-than-substr On Wed, Apr 10, 2013 at 3:46 PM, kavita kulkarni kavitahkulka...@gmail.comwrote: Hi All, I want to extract certain char sets (e.g. char 4 to 9, char 11 to 14 etc.) from each line of my file and store them in separate variables for further processing. My file size can vary from thousand to millions of lines. If I use perl in-built function substr() to data extraction, it has huge impact on performance. Is there any alternative for this? Please can you give example of what you want done and show how you are going about it? Thanks in advance. Cheers, Kavita -- Regards, Chankey Pathak http://www.linuxstall.com
Re: Any alternative for substr() function
From: timothy adigun 2teezp...@gmail.com On 10 Apr 2013 11:30, Chankey Pathak chankey...@gmail.com wrote: Hi Kavita, You may try unpack (http://perldoc.perl.org/functions/unpack.html) unpack would not work if the OP has varying length of lines. Nope. It would work just fine as long as the bits he's interested in are fixed lengh and are on fixed positions. The length of the uninteresting trailing stuff is irrelevant. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Win32 - Killing Processes - update possible solution
From: Jonathan Harris jtnhar...@googlemail.com As it seems that Win32::Process::KillProcess is having difficulties killing a hanging process, I thought that it would probably make sense to ask the system to do it directly So, in the sub 'kill_it', I have replaced the line Win32::Process::KillProcess ($new_pid, \$exitcode); with system 'Taskkill /PID ' . ($new_pid); I am using 'system' rather than 'exec' as it returns a success status; 'exec' is silent in this respect The fairly confusingly named fuction exec() never returns! It's supposed to be used if you are done executing your program and want to switch to executing a different one ... usually after you fork()ed ... that is cloned the process. The way processed are started in unix is a little ... awkward. Instead of telling the system you want to execute some program with some parameters, you are supposed to split in two and in one of the clones, after you are finished setting things up, morph into another program. Kinda hacky. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Any alternative for substr() function
Data file has the lines with same length and so the field positions I am interested in (so unpack works for me). Tried with unpack as well it takes almost same time as substr(). Here is sample code: Below function is called for each line of input data file.. sub extractFieldValue { my $self = shift; my $data = shift; #Line from data file my $start = shift; my $length = shift; my $startPos = $start - 1; my $val = unpack(a$length, $data); $val =~ s/\|/ /g; return $val; } $val is then used as key of a Hash for further processing. Cheers, Kavita Regards, Kavita :-) On Wed, Apr 10, 2013 at 4:32 PM, Jenda Krynicky je...@krynicky.cz wrote: From: timothy adigun 2teezp...@gmail.com On 10 Apr 2013 11:30, Chankey Pathak chankey...@gmail.com wrote: Hi Kavita, You may try unpack (http://perldoc.perl.org/functions/unpack.html) unpack would not work if the OP has varying length of lines. Nope. It would work just fine as long as the bits he's interested in are fixed lengh and are on fixed positions. The length of the uninteresting trailing stuff is irrelevant. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Win32 - Killing Processes - update possible solution
On Wed, Apr 10, 2013 at 12:02 PM, Jenda Krynicky je...@krynicky.cz wrote: From: Jonathan Harris jtnhar...@googlemail.com As it seems that Win32::Process::KillProcess is having difficulties killing a hanging process, I thought that it would probably make sense to ask the system to do it directly So, in the sub 'kill_it', I have replaced the line Win32::Process::KillProcess ($new_pid, \$exitcode); with system 'Taskkill /PID ' . ($new_pid); I am using 'system' rather than 'exec' as it returns a success status; 'exec' is silent in this respect The fairly confusingly named fuction exec() never returns! It's supposed to be used if you are done executing your program and want to switch to executing a different one ... usually after you fork()ed ... that is cloned the process. The way processed are started in unix is a little ... awkward. Instead of telling the system you want to execute some program with some parameters, you are supposed to split in two and in one of the clones, after you are finished setting things up, morph into another program. Kinda hacky. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ Hi Jenda Thanks for the clarification on exec() and 'system' Processes in Unix have so far seemed easier to handle - if you want them destroyed, a 'kill -9' signal really does the job! In Windows, the steps have not appeared as straight forwards as there are a few different ways to end a process - taskkill, process -k etc etc Hopefully, the taskkill will do the job! Thanks for your input Jon
Re: Any alternative for substr() function
G'Mornin' Kavita -- Before you go off on a goose chase, how do you know that substr() is going to be a problem for you? Have you bench-marked it? If your file is as large as you say, I strongly suspect that your bottleneck is going to be I/O and any differences between unpack() and substr() will be lost in the noise band below 1%. B On Wed, Apr 10, 2013 at 5:02 AM, kavita kulkarni kavitahkulka...@gmail.comwrote: Data file has the lines with same length and so the field positions I am interested in (so unpack works for me). Tried with unpack as well it takes almost same time as substr(). Here is sample code: Below function is called for each line of input data file.. sub extractFieldValue { my $self = shift; my $data = shift; #Line from data file my $start = shift; my $length = shift; my $startPos = $start - 1; my $val = unpack(a$length, $data); $val =~ s/\|/ /g; return $val; } $val is then used as key of a Hash for further processing. Cheers, Kavita Regards, Kavita :-) On Wed, Apr 10, 2013 at 4:32 PM, Jenda Krynicky je...@krynicky.cz wrote: From: timothy adigun 2teezp...@gmail.com On 10 Apr 2013 11:30, Chankey Pathak chankey...@gmail.com wrote: Hi Kavita, You may try unpack (http://perldoc.perl.org/functions/unpack.html) unpack would not work if the OP has varying length of lines. Nope. It would work just fine as long as the bits he's interested in are fixed lengh and are on fixed positions. The length of the uninteresting trailing stuff is irrelevant. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- Bob Goolsby bob.gool...@gmail.com
Re: Any alternative for substr() function
On Wed, 10 Apr 2013 08:45:40 -0700 Bob goolsby bob.gool...@gmail.com wrote: Before you go off on a goose chase, how do you know that substr() is going to be a problem for you? Have you bench-marked it? If your file is as large as you say, I strongly suspect that your bottleneck is going to be I/O and any differences between unpack() and substr() will be lost in the noise band below 1%. ^^ This. Kavita, I'd strongly advise profiling your script with Devel::NYTProf to see exactly where the time is being spent; it can be a surprise sometimes. Once you've got some profiling data showing you where the most time is spent, you know where to focus your efforts. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Any alternative for substr() function
As others have mentioned, you should profile the program to get an idea of what code is taking up time. That said, here are a couple of comments: When you have that many arguments, it is usually preferrable (may be a little faster) to use the following (rather than shifts): my ($self, $data, $start, $length) = @_; That said, if you can, get rid of arguments you aren't using. Also, you are setting a variable named $startPos, and never using it. Also, for your regular expression, utilize the qr operator: my $regexp = qr#\|#; sub extractFieldValue { ... ... $val =~ s/$regexp/ /g; ... } HTH, Ken On Wed, Apr 10, 2013 at 8:02 AM, kavita kulkarni kavitahkulka...@gmail.comwrote: Data file has the lines with same length and so the field positions I am interested in (so unpack works for me). Tried with unpack as well it takes almost same time as substr(). Here is sample code: Below function is called for each line of input data file.. sub extractFieldValue { my $self = shift; my $data = shift; #Line from data file my $start = shift; my $length = shift; my $startPos = $start - 1; my $val = unpack(a$length, $data); $val =~ s/\|/ /g; return $val; } $val is then used as key of a Hash for further processing. Cheers, Kavita Regards, Kavita :-) On Wed, Apr 10, 2013 at 4:32 PM, Jenda Krynicky je...@krynicky.cz wrote: From: timothy adigun 2teezp...@gmail.com On 10 Apr 2013 11:30, Chankey Pathak chankey...@gmail.com wrote: Hi Kavita, You may try unpack (http://perldoc.perl.org/functions/unpack.html) unpack would not work if the OP has varying length of lines. Nope. It would work just fine as long as the bits he's interested in are fixed lengh and are on fixed positions. The length of the uninteresting trailing stuff is irrelevant. Jenda = je...@krynicky.cz === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Any alternative for substr() function
On 10/04/2013 16:45, Bob goolsby wrote: G'Mornin' Kavita -- Before you go off on a goose chase, how do you know that substr() is going to be a problem for you? Have you bench-marked it? If your file is as large as you say, I strongly suspect that your bottleneck is going to be I/O and any differences between unpack() and substr() will be lost in the noise band below 1%. Hint: Try adding return ; as the first statement of `extractFieldValue` (i.e. so that it does nothing and returns a null string) then run your program and see how long it takes just doing the IO. Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/