Answer the question
In order to leave comments, you need to log in
Linux thread pids?
Hello, a question about Linux threads - should each thread have its own PID?
Issue resolved.
There is this code:
#!/usr/bin/perl -w
use strict;
use warnings;
use threads;
my $thread_num = 20;
my @threads;
foreach (1..$thread_num) {
push @threads, threads->create(\&calc);
}
foreach my $thread ( @threads ) {
my $thread_end = $thread->join ;
print "Thread [ $thread_end ] Ending ... \n";
}
sub calc {
my $count = 0;
foreach (1..1000000000){
$count += $_;
}
return $count;
}
Answer the question
In order to leave comments, you need to log in
Everything is correct.
1) use threads; does not use fork (although the implementation, neither by design nor by the real picture, does not outperform fork in anything, under linux)
2) different pids are needed - try use forks or use fork
3) The process has one PID
4) man pstree
Child threads of a process are found under the parent process and are shown with the process name in curly braces, eg
5) htop - press letter 'H' this will show/disable threads
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question