{"id":8,"date":"2021-01-11T09:20:41","date_gmt":"2021-01-11T09:20:41","guid":{"rendered":"https:\/\/veltzer.net:8890\/?p=8"},"modified":"2021-01-11T09:39:03","modified_gmt":"2021-01-11T09:39:03","slug":"finding-thread-info-on-solaris","status":"publish","type":"post","link":"https:\/\/veltzer.net:8890\/finding-thread-info-on-solaris\/","title":{"rendered":"Finding thread info on Solaris"},"content":{"rendered":"\n
As part of a crusade to find bugs in a C++ program running on a Solaris system I needed to find out information about all the threads belonging to a certain process.<\/p>\n\n\n\n
The program is written the way it is because you rarely need thread info about all threads running in a system but rather threads limited to a certain process. A different way to get this info is through the \/proc file system but unfortunately (or fortunately ?!?) files in this Solaris file system usually have binary content as opposed to the textual content that one usually finds on a Linux system.<\/p>\n\n\n\n
#!\/usr\/bin\/perl -w\n \n# Give this script the name of a process and it will show you thread\n# infomation about your process...\n \n \nuse strict;\nuse diagnostics;\n \n \nif(@ARGV<1) {\n die(\"usage myps.pl [process names...]\");\n}\n \n \nfor(my($p)=0;$p<@ARGV;$p++) {\n my($pname)=$ARGV[$p];\n print \"showing diagnostics information for process $pname\\n\";\n \n \n # first lets find out the pid of the process\n my($pid)=`pgrep $pname`;\n chop($pid);\n print \"The process id of the process is $pid\\n\";\n \n \n # now lets print all the thread info for that process...\n my(@lines)=`ps -eL`;\n for(my($i)=0;$i<@lines;$i++) {\n my($line)=$lines[$i];\n my(@fields)=split(\" \",$line);\n if($fields[0] eq $pid) {\n print $line;\n #print(join('-',@fields));\n }\n }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"As part of a crusade to find bugs in a C++ program running on a Solaris system I needed to find out information about all the threads belonging to a certain process. The program is written the way it is because you rarely need thread info about all threads running in a system but rather … <\/p>\n