Skip to content

Instantly share code, notes, and snippets.

@quant61
Created July 17, 2022 10:40
Show Gist options
  • Save quant61/77921ee62095f248ce49b540a2d0ae88 to your computer and use it in GitHub Desktop.
Save quant61/77921ee62095f248ce49b540a2d0ae88 to your computer and use it in GitHub Desktop.
Find processes which are using files in /dev/shm
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
// TODO: write it in asm
func main() {
d, _ := os.Open("/proc")
pp, _ := d.Readdirnames(9000)
for _, p := range pp {
b, _ := ioutil.ReadFile(fmt.Sprintf("/proc/%s/maps", p))
ll := strings.Split(string(b), "\n")
for _, l := range ll {
if strings.Contains(l, "/dev/shm") {
fmt.Println(p, l)
}
}
dfd, _ := os.Open(fmt.Sprintf("/proc/%s/fd", p))
fdd, _ := dfd.Readdirnames(9000)
dfd.Close()
for _, fd := range fdd {
lnk, _ := os.Readlink(fmt.Sprintf("/proc/%s/fd/%s", p, fd))
if strings.HasPrefix(lnk, "/dev/shm") {
fmt.Println(p, fd, lnk)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment