Skip to content

Instantly share code, notes, and snippets.

@quant61
Created July 17, 2022 10:40

Revisions

  1. quant61 created this gist Jul 17, 2022.
    33 changes: 33 additions & 0 deletions find-shm-mentions.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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)
    }
    }
    }
    }