Created
July 17, 2022 10:40
-
-
Save quant61/77921ee62095f248ce49b540a2d0ae88 to your computer and use it in GitHub Desktop.
Find processes which are using files in /dev/shm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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