Re: thred's pids

[email protected] (Mihai Vlad)
Newsgroups perl.ithreads
Message-ID <[email protected]>
David Greaves wrote:

> Mihai Vlad wrote:
>
>> none of these return the actupa pid of the thread:( (or at least i 
>> can't interpret it)
>>
>> here-s what i get:
>>
>> threads=SCALAR(0x81733b4)=SCALAR(0x8173390)
>> 135846736
>> 1
>>
>> when these threds were running ps ax gave me these:
>> 25234 pts/4    S+     0:00 /usr/bin/perl ./test
>> 25235 pts/4    S+     0:00 /usr/bin/perl ./test
>> 25236 pts/4    S+     0:00 /usr/bin/perl ./test
>>
>> I'm interested in the number 25236 wich i'm sure is the pid to my 
>> opened thred , how can i get this number just using perl and it's 
>> modules? :( i've tryied like anything.... now i'm trying to see the 
>> code in how a thread is created perhaps there is something there, if 
>> you know already or know a better way pls tell me.
>> 10x
>
>
> OK
> That's what I expect. The tid of your thread ($thr1) is 1.
>
> 25235 that's beyond my knowledge level :)
>
> From reading the docs, I'm pretty sure that you're not supposed to 
> look at it - it's implementation specific.
> I'd expect some systems not to have a per-thread OS-level pid - indeed 
> linux may not in the future.
>
> Why do you need to?
>
> Are you wanting to use signals? In which case set the signal handler 
> in the thread and signal() the master PID.
> See if that works.
> I'd expect it to be threadsafe given the docs caveat:
> If your Perl has been built with PERL_OLD_SIGNALS (one has to 
> explicitly add that symbol to ccflags, see |perl -V|), signal handling 
> is not threadsafe.
>
> David
>
>
>
No, i have a test script written in perl, that starts over 1000 threads 
that read/write on a specific socket , every thread logs it's actions on 
a single file called threadTID.log. Sometimes some of the threads don't 
close (the script is safely made: i mean no write or read is left 
unlogged or unsupervised, if a single write failes the thread is killed) 
so i'm suspecting that the program i'm testing is to blame for.
Now it would be very easy to identify the logs of the hanging threads if 
they would be something like thrPID.log.

Of course i've implemented a more simple solution like: writing 
something at the end of a log when the thread closes:P and by this way 
making it easy for my to identify the remaining threads logs.
But i was curious if i could find the threads pid and implemente like 
i've written above for future knolledge, and scripts:). I know that 
threads written in C and other languages know their pids, so i'm really 
curious if i can find this in perl...

Regarding the signals i am aware of the %SIG hash.

-- 
Mihai Vlad
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.