September 2008 Archives

Solaris下调试程序方法:使用truss

From: http://blog.chinaunix.net/u1/42574/showart_489928.html

Solaris下调试程序方法:使用truss

truss 介绍

solaris下的truss跟linux下的strace功能一样,用来跟踪系统/库函数调用和系统接收到的信号。并把函数调用跟信号发送到标准出错上。

truss 使用方法

truss  -a  -e  -f  -rall  -wall  -p

truss  -a  -e  -f  -rall  -wall


-a        显示传递给exec函数的参数
-e        显示传递给exec函数的环境变量
-f         显示子进程
-rall     显示所有读取的数据(默认32bytes)
-wall    显示所有写的数据(默认32bytes)
-p        Hook到一个已存在的进程(必须是进程的所有者或者root)
-d        显示跟踪进程运行的时间
<program> 指定要运行的程序

truss 例子

# truss -rall -wall -f -p <PID>
# truss -rall -wall lsnrctl start
# truss -aef lsnrctl dbsnmp_start
0
# truss -d date

Base time stamp:  1066157908.5731  [ Tue Oct 14 14:58:28 EDT 2003 ]

 0.0000 execve("/usr/bin/date", 0xFFBEF29C, 0xFFBEF2A4)  argc = 1

 0.0449 mmap(0x00000000, 8192, PROT_READ|PROT_WRITE|PROT_EXEC,MAP_PRIVATE|MAP_ANON, -1, 0) = 0xFF3A0000

 0.0453 resolvepath("/usr/lib/ld.so.1", "/usr/lib/ld.so.1", 1023) = 16

 0.0457 open("/var/ld/ld.config", O_RDONLY)             Err#2 ENOENT

 0.0460 open("/usr/lib/libc.so.1", O_RDONLY)            = 3

 0.0463 fstat(3, 0xFFBEE9C4)                            = 0

 0.0464 mmap(0x00000000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xFF390000

 0.0466 mmap(0x00000000, 794624, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xFF280000

 0.0470 mmap(0xFF33A000, 24652, PROT_READ|PROT_WRITE|PROT_EXEC,MAP_PRIVATE|MAP_FIXED, 3, 696320) = 0xFF33A000

 0.0474 munmap(0xFF32A000, 65536)                       = 0

 0.0479 memcntl(0xFF280000, 113332, MC_ADVISE, MADV_WILLNEED, 0, 0) = 0

 0.0481 close(3)                                        = 0

 0.0483 open("/usr/lib/libdl.so.1", O_RDONLY)           = 3

 0.0485 fstat(3, 0xFFBEE9C4)                            = 0

 0.0487 mmap(0xFF390000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED,3, 0) = 0xFF390000

 0.0490 close(3)                                        = 0

 0.0493 open("/usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1", O_RDONLY) = 3

 0.0496 fstat(3, 0xFFBEE854)                            = 0

 0.0497 mmap(0x00000000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xFF380000

 0.0500 mmap(0x00000000, 16384, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xFF370000

 0.0502 close(3)                                        = 0

 0.0514 munmap(0xFF380000, 8192)                        = 0

 0.0521 brk(0x00022420)                                 = 0

 0.0523 brk(0x00024420)                                 = 0

 0.0526 time()                                          = 1066157908

 0.0531 open("/usr/share/lib/zoneinfo/US/Eastern", O_RDONLY) = 3

 0.0533 read(3, " T Z i f\0\0\0\0\0\0\0\0".., 8192)     = 1250

 0.0536 close(3)                                        = 0

 0.0542 ioctl(1, TCGETA, 0xFFBEEFDC)                    = 0

Tue Oct 14 14:58:28 EDT 2003

 0.0545 write(1, " T u e   O c t   1 4   1".., 29)      = 29

 0.0547 llseek(0, 0, SEEK_CUR)                          = 1829

 0.0549 _exit(0)
From: http://blog.csdn.net/Adali/archive/2007/11/23/1899779.aspx

Solaris平台上如何知道某个端口被哪个进程和应用程序占用

我经常在Solaris服务器上启好几个Tomcat和GlassFish, 会遇到"端口"被占用的错误, 很难直接用命令得知这个端口到底被哪个进程或者应用程序占用了, Alex给了我三个解决方案。附带说一句,我只尝试了第一种方案,相当的好用。而Alex愿意花时间找解决方案,却不愿意花几分钟把这些好东西写出来,结果就是被我发表出来。功劳还是要归Alex Peng.

第一种方案:

1。使用下面shell script,先建立一个port.sh文件:

# more /tmp/port.sh

#!/bin/sh

for pid in `ls /proc`

do

       pf=`/usr/bin/pfiles $pid 2>/dev/null`

       if echo $pf | grep $1 > /dev/null 2>&1

       then

           echo $pid

           /usr/bin/pargs $pid

       fi

done

2。运行port.sh, 传入端口号,比如53250 :

#  /tmp/port.sh 53250

3。运行结果如下:

1225

1225:   /usr/lib/thunderbird/thunderbird-bin -UILocale zh-CN

-contentLocale CN

argv[0]: /usr/lib/thunderbird/thunderbird-bin

argv[1]: -UILocale

argv[2]: zh-CN

argv[3]: -contentLocale

argv[4]: CN

4212

4212:   /bin/sh /tmp/port.sh 53250

argv[0]: /bin/sh

argv[1]: /tmp/port.sh

argv[2]: 53250

 
第二种方案:

下载"lsof" package。但可能不适合每种情况


第三种方案:

使用MDB

   from socket info (netstat output), you can know its vnode

   from vnode info, you can know which process owns it

   from process info, you can know its args, so comes the result.

 
Reference

lsof:

http://dmiessler.com/study/lsof/
http://freshmeat.net/projects/lsof/

MDB:

Solaris™ Performance and Tools: DTrace and MDB Techniques for Solaris 10 and OpenSolaris

Introduction to Unix Communication Tools

From: http://www.helpdesk.umd.edu/systems/glue/applications/pine/1112/

Introduction to Unix Communication Tools

There are several communications and networking tools that are available on nearly every UNIX system. This document will go over a handful of the more standard ones, including clients that allow you to login remotely, transfer files, send e-mail, and talk (or refuse to talk) in real-time.

About this Archive

This page is an archive of entries from September 2008 listed from newest to oldest.

August 2008 is the previous archive.

July 2009 is the next archive.

Find recent content on the main index or look in the archives to find all content.