package main
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"syscall"
)
func ShowProcessInfo(pid int) {
err := syscall.PtraceAttach(pid)
if err != nil {
panic(err)
}
_, err = syscall.Wait4(pid, nil, 0, nil)
if err != nil {
panic(err)
}
var regs syscall.PtraceRegs
err = syscall.PtraceGetRegs(pid, ®s)
if err != nil {
panic(err)
}
err = syscall.PtraceDetach(pid)
if err != nil {
panic(err)
}
fmt.Println("pid:", pid)
fmt.Println(regs.Rsp)
}
func ShowProcessStack(pid string) {
dirs, err := ioutil.ReadDir(fmt.Sprintf("/proc/%s/task", pid))
if err != nil {
panic(err)
}
for _, dir := range dirs {
sub_pid, _ := strconv.ParseInt(dir.Name(), 10, 32)
ShowProcessInfo(int(sub_pid))
}
}
func main() {
ShowProcessStack(os.Args[1])
}
网友评论