thread count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting thread count
# 8  
Old 06-10-2009
Quote:
Originally Posted by radoulov
You should use something like this:

Code:
 ++$TIDcount 
    if / tid (\d+)/ && !$tidUnique{$1}++;

Given you sample data:

Code:
% perl -nle'
  ++$c if / tid (\d+)/ && !$tid{$1}++;
  print $c if eof
  ' infile
2

Hi Radoulov,

what is $tidUnique here? how it is going to work in my case. Can you suggest me in my code.
when i used the code like this-
Code:
my $TIDCount = 0;
while(my $line = <$log>) { 
    # Outer loop. Look for an interesting part of the log file. 
	$n++; 
    $line =~ tr/\r\n//d; 
	++$TIDcount ;
    if /tid (\d+)/ && !$tidUnique{$1}++;
        next;
	
}
print "Thread count for the logfile is $TIDCount\n";

it gave me these errors
syntax error at tid_count.pl line 17, near "if /tid (\d+)/"
syntax error at tid_count.pl line 17, near "++;"
syntax error at tid_count.pl line 20, near "}"
Execution of tid_count.pl aborted due to compilation errors.


Thanks
NT
# 9  
Old 06-10-2009
Try this:

Code:
#!/usr/bin/perl

use warnings;
use strict;

print "Hello, World...\n";

my $logFile = shift;
my ( $TIDCount, %TIDUnique );

die "usage: $0 <logFile>\n" unless defined $logFile;

die "Logfile $logFile doesn't exist\n" unless -f $logFile;

open my $log, $logFile or die "Can't open $logFile for reading\n";

print "Processing file $logFile...\n";

while (<$log>) {
    ++$TIDCount
      if / tid (\d+)/ && !$TIDUnique{$1}++;
}

print "Thread count for the logfile is $TIDCount\n";

# 10  
Old 06-10-2009
Hi Radoulov,

Thank you very much, it worked for me.
I need to dig alot to learn perl.

Thanks
NT
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Not able to post thread/reply to thread

Dear Moderator I am not able to post any new thread or post reply to mine old thread. Kindly help as i am stuck on one problem and needed suggestion. Regards Jaydeep (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies

2. UNIX for Dummies Questions & Answers

Thread count for a process id

Hi, I want to know a command/program to get thread count for a process id in unix box. Please help me in this regard. (1 Reply)
Discussion started by: manaac
1 Replies

3. Solaris

thread count using top

I am running a multithreaded program which creates 10 threads and works away. However, when I use top to monitor my program whilst it is running, it only shows 4 under the thread count! Can anyone explain if this is in fact the number of threads running in my process... (0 Replies)
Discussion started by: supahoop
0 Replies

4. Programming

How to cancel a thread safely from the initial thread?

how about asynchronous canceling? or with signal? if with signal whether it effects the process? my english so badly :( :( (1 Reply)
Discussion started by: alan.zhao
1 Replies
Login or Register to Ask a Question