<commit_before>
package pidinfo

import (
    "os"
    "io/ioutil"
    "fmt"
    "strconv"
)

type ProcessInfo struct {
    Pid int
    Cmd string
    Args []string
}

func lookupProcess(pid int) ProcessInfo {
    var info ProcessInfo
    info.Pid = pid

    var cmdPath string = fmt.Sprintf("/proc/%d/comm", pid)
    if cmd, err := ioutil.ReadFile(cmdPath); err == nil {
        info.Cmd = string(cmd)
    }
    return info
}

func scanProcessForInode(inode, pid int) bool {
    var inodePattern = fmt.Sprintf("socket:[%d]", inode)
    var path = fmt.Sprintf("/proc/%d/fd/", pid);
    if fds, err := ioutil.ReadDir(path); err == nil {
        for _, value := range(fds) {
            if link, err := os.Readlink(path + value.Name()); err == nil {
                if (link==inodePattern) {
                    return true;
                }
            }
        }
    }
    return false;
}

func ScanProcessesForInode(inode int) *ProcessInfo {
    if processes, err := ioutil.ReadDir("/proc"); err == nil {
        for _, value := range(processes) {
            if pid, err := strconv.Atoi(value.Name()); err == nil {
                if scanProcessForInode(inode, pid) {
                    fmt.Printf("inode found in pid %d\n", pid);
                    var processInfo = lookupProcess(pid);
                    return &processInfo
                }
            }
        }
    }
    return nil<commit_msg>Add some comments and renamed a few functions.<commit_after>// Package pidinfo implements various functions related to PID:s and
// processes.
package pidinfo

import (
    "os"
    "io/ioutil"
    "fmt"
    "strconv"
)

// ProcessInfo contains meta information for a process.
type ProcessInfo struct {
    Pid int
    Cmd string
    Args []string
}

// LookupProcess returns a ProcessInfo reference for process given by pid.
func LookupProcess(pid int) *ProcessInfo {
    var info ProcessInfo
    info.Pid = pid

    var cmdPath string = fmt.Sprintf("/proc/%d/comm", pid)
    if cmd, err := ioutil.ReadFile(cmdPath); err == nil {
        info.Cmd = string(cmd)
    }
    return &info
}

// FindProcessForInode returns a ProcessInfo reference for the process that
// owns the given inode.
func FindProcessForInode(inode int) *ProcessInfo {
    return scanProcessesForInode(inode);
}

func scanProcessForInode(inode, pid int) bool {
    var inodePattern = fmt.Sprintf("socket:[%d]", inode)
    var path = fmt.Sprintf("/proc/%d/fd/", pid);
    if fds, err := ioutil.ReadDir(path); err == nil {
        for _, value := range(fds) {
            if link, err := os.Readlink(path + value.Name()); err == nil {
                if (link==inodePattern) {
                    return true;
                }
            }
        }
    }
    return false;
}

func scanProcessesForInode(inode int) *ProcessInfo {
    if processes, err := ioutil.ReadDir("/proc"); err == nil {
        for _, value := range(processes) {
            if pid, err := strconv.Atoi(value.Name()); err == nil {
                if scanProcessForInode(inode, pid) {
                    fmt.Printf("inode found in pid %d\n", pid);
                    return LookupProcess(pid);
                }
            }
        }
    }
    return nil
{'fraction_non_alphanumeric': 0.11904019943907759, 'fraction_numerical': 0.0, 'mean_word_length': 2.0140845070422535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '555683', 'n_tokens_mistral': 975, 'n_tokens_neox': 954, 'n_words': 271}