linux查看堆棧
A. linux應用中,在一個進程內如何獲取本進程內其它線程的堆棧信息、
用
pthread_getattr_np
(pthread_t
tid,
pthread_attr_t
*attr);
即可。
具體你需要先了解一下pthread
相關介面。
比如,
#define
_GNU_SOURCE
/*
See
feature_test_macros(7)
*/
#include
<pthread.h>
int
main()
{
...
tid
=
pthread_create(xxxx,xxx...);
...
pthread_getattr_np(tid,
&attr);
/*
後面就可以用
pthread_attr_getstack
之類的介面從
attr
中獲得這個線程的
stack
信息(比如地址,大小等)*/
}
B. linux如何查找到某一個進程在調用哪些文件
1、查看進程「打開」的文件 (方法1): 1)pidof programe-name(獲得想了解的進程(programe-name)的PID) 或ps -aux|grep programe-name(獲得想了解的進程(programe-name)的PID) 找出進程的PID 2)cd /proc/$PID/fd(會看見文件描述符) 3)ls -l 得到文件描述符指向的實際文件,即當前進程打開的文件2、查看進程「打開」的文件 (方法2): 1)獲得想了解的進程的PID方法同上 2)lsof -c programe-name 或lsof -p $PID
C. linux ps命令顯示一個特定的進程信息,如下說明
ps
ps(即進程狀態)命令用於提供有關當前正在運行的進程的信息,包括其進程標識號(PID)。
進程,也稱為任務,是程序的執行(即,運行)實例。系統為每個進程分配一個唯一的PID。
ps的基本語法是
ps [options]
當沒有任何選項使用ps時,它會發送到標准輸出,默認情況下是顯示監視器,系統上當前至少有兩個進程的四項信息:shell和ps。shell是一個程序,它在類Unix操作系統中提供傳統的純文本用戶界面,用於發出命令並與系統交互,默認情況下在Linux上是bash。ps本身是一個進程,一旦顯示輸出它就會死掉(即終止)。
使用ps獲取有關系統當前進程的更完整信息的常用方便方法是使用以下方法:
ps -aux | less
ps顯示的進程可以限制為屬於任何給定用戶的進程,方法是通過grep(一種用於搜索文本的過濾器)輸出輸出。例如,屬於具有用戶名adam的用戶的進程可以使用以下內容顯示:
ps -ef | grep adam
Linux 下 取進程佔用 cpu 最高的前10個進程
ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head
linux 下 取進程佔用內存(MEM)最高的前10個進程
ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head
其中rsz是是實際內存
$ ps -e -o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid'
$ ps -e -o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid' | grep oracle | sort -nrk5
其中rsz為實際內存,上例實現按內存排序,由大到小
5個命令檢查Linux中內存使用情況,含PS
D. linux 怎麼查看segmentation fault堆棧
gdb ExeName
(gdb)core core.xx
(gdb)bt
core mp 一般是在segmentation fault(段錯誤)的情況下產生的文件,需要通過ulimit來設置才會得到的。關於Linux命令的介紹,看看《linux就該這么學》,具體關於這一章地址3w(dot)linuxprobe/chapter-02(dot)html.
E. 1 linux下調試core的命令,察看堆棧狀態命令
比方說,你要調試的core文件是 core.xxx,原始可執行文件是 a.exe
先用 gdb a.exe 進入 gdb,在gdb命令行下 執行
core-file /path/to/core.xxx
然後即可調試core mp文件了,比如用 bt 等
F. linux查看文件被哪些進程使用
可以使用:ps
-fe|grep
filename,
也可以使用:fuser
filename查看
然後可以看這個進程跟哪裡東西有關聯,使用了哪些埠
只查看該進程:ps
-ef
|
grep
ID
查看該進程打開的文件:lsof
-p
ID
查看內存分配:lcat
/proc/ID/maps
查看堆棧:pstack
11ID
查看發出的系統調用:strace
-p
ID
查看調用庫函數:ltrace
-p
ID
G. linux中如何查看某個文件被哪些進程佔用
查看進程
在Linux要檢查那一個進程(process)佔用特定埠號,可以用netstat或lsof來做,例如想列出所有開啟的埠號,可以netstat指令:
或者:
我們已經知道我們想要殺死的那個進程的名字,我們能夠利用killall命令發送同樣的信號,像這樣:
killall -9 mongod
H. linux 查看文件被哪個進程佔用
1.只查看該進程:ps -ef | grep 11345
2.查看該進程打開的文件:lsof -p 11345
3.查看內存分配:lcat /proc/11345/maps
4.查看堆棧:pstack 11345
5.查看發出的系統調用:strace -p 11345
6.查看調用庫函數:ltrace -p 11345
I. linux應用中,在一個進程內如何獲取本進程內其它線程的堆棧信息、
先用ps看目前存在的所有進程的進程號,然後可以對具體進程採用以下這些操作:(11345就是對應具體的進程號)
只查看該進程:ps -ef | grep 11345
查看該進程打開的文件:lsof -p 11345
查看內存分配:lcat /proc/11345/maps
查看堆棧:pstack 11345
查看發出的系統調用:strace -p 11345
查看調用庫函數:ltrace -p 11345
J. Linux 怎麼查看一個進程的堆棧
方法一:pstack pid
NAME
pstack - print a stack trace of a running process
SYNOPSIS
pstack pid
DESCRIPTION
pstack attaches to the active process named by the pid on the command line, and prints out an execution stack trace. If ELF symbols exist in the binary (usually the case
unless you have run strip(1)), then symbolic addresses are printed as well.
If the process is part of a thread group, then pstack will print out a stack trace for each of the threads in the group.
SEE ALSO
nm(1), ptrace(2), gdb(1)
方法二:gstack pid
NAME
gstack - print a stack trace of a running process
SYNOPSIS
gstack pid
DESCRIPTION
gstack attaches to the active process named by the pid on the command line, and prints out an execution stack trace. If ELF symbols exist in the binary (usually the case
unless you have run strip(1)), then symbolic addresses are printed as well.
If the process is part of a thread group, then gstack will print out a stack trace for each of the threads in the group.
SEE ALSO
nm(1), ptrace(2), gdb(1)
方法三:
使用gdb 然後attach 進程ID,然後再使用命令 thread apply all bt。
方法一和方法二一樣,方法三可以查看更多的信息。