README
¶
pfinder: Cross-Platform Process Finder
pfinder
is a cross-platform tool written in Go that helps you find processes based on various criteria, such as file usage, PID, command strings, regex patterns, and network ports.
Designed to be efficient and robust,
pfinder
works seamlessly on both macOS and Linux without relying on external system commands.
Features
- Cross-Platform Compatibility: Supports macOS and Linux with platform-specific optimizations.
- Find Processes by File Usage: Identify which process is using a specific file or directory.
- Find Processes by PID: Retrieve detailed information about a process by its PID.
- Find Processes by Command String or Regex: Filter running processes based on command strings or regex patterns.
- Find Processes by Port: Identify processes listening on a specific network port.
- Efficient and Concurrent: Utilizes Go's concurrency features to handle large numbers of processes efficiently.
- Pure Go Implementation: No external dependencies or system commands required.
Installation
To build pfinder
from source, follow these steps:
Prerequisites
-
Install Go: Ensure you have Go installed. You can download and install Go from golang.org.
-
Set Up Go Environment: Configure your Go environment variables, especially
GOPATH
, which is the directory where your Go workspace is located.
Steps to Build
-
Clone the Repository: Clone the
pfinder
repository from GitHub to your local machine.git clone https://github.com/hemzaz/pfinder.git cd pfinder
-
Install Dependencies: Install the required Go packages.
go get github.com/mitchellh/go-ps go get github.com/shirou/gopsutil/net
-
Build the Executable: Use the
go build
command to compile the source code into an executable.go build -o pfinder
-
Verify the Executable: Ensure the
pfinder
executable is created in the current directory.ls -l pfinder
Usage
pfinder
can be used with multiple arguments to find processes based on various criteria. The results will be aggregated and displayed.
./pfinder <arguments>...
Arguments
- Path: If the argument is a path to an existing file or folder,
pfinder
reports the PID locking the resource (if any). - PID: If the argument is a PID,
pfinder
provides detailed information about the process. - String: If the argument is a string,
pfinder
filters running processes case-insensitively based on the string in their command line. - Regex: If the argument is a regex,
pfinder
filters running processes using the regex pattern. - Port: If the argument is a port (prefixed with ':'),
pfinder
reports the processes listening on that port.
Examples
-
Find the process using a specific file:
./pfinder /path/to/file
-
Get details of a process by PID:
./pfinder 1234
-
Find processes by a command string:
./pfinder "go run"
-
Find processes by a regex pattern:
./pfinder ".*go.*"
-
Find processes by a port:
./pfinder :8080
-
Aggregate multiple arguments:
./pfinder "go run" :8080 /path/to/file
How It Works
Path Handling
- macOS: Uses native Go libraries to check file usage by iterating over processes and their file descriptors.
- Linux: Reads the
/proc
filesystem to check which process is using the specified file or directory.
PID Handling
- Retrieves detailed information about the process including PID, PPID, user, and command.
String and Regex Handling
- Filters running processes based on command strings or regex patterns in a case-insensitive manner.
Port Handling
- Uses the
gopsutil
library to identify processes listening on specified network ports.
Contributing
We welcome contributions! Here are a few ways you can help:
- Report Bugs: Use the issue tracker to report bugs.
- Fix Bugs: If you find a bug and know how to fix it, please do so! Pull requests are welcome.
- Request Features: If you have ideas for new features, we'd love to hear them.
How to Contribute
- Fork the repository
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
Acknowledgements
- mitchellh/go-ps: A library for listing processes on a system.
- shirou/gopsutil: A library for retrieving system and process information.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Authored by: hemzaz the frogodile 🐸🐊
Documentation
¶
There is no documentation for this package.