Skip to content

ice3x2/win_ps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

win_ps

A GNU-style ps command for Windows that brings Linux process management familiarity to Windows environments.

License: MIT Platform Version

Table of Contents


🎯 Overview

win_ps provides a familiar Linux-style process listing experience on Windows without requiring administrator privileges. It automatically handles encoding for seamless integration with Java, Python, and other tools.

Key Features

  • GNU-compatible: Supports standard options like -ef, -fl, -l
  • Smart Encoding: Auto-detects console vs pipe for optimal output
  • Flexible Output: Custom columns, multi-key sorting, filtering
  • No Admin Required: Works with standard user privileges
  • Windows 2008+: Compatible with legacy and modern Windows versions

πŸ“₯ Installation

Download Binary

Download the latest win_ps.exe from Releases and add it to your PATH.

Build from Source

Requirements: Visual Studio 2022 or MSBuild tools

git clone https://github.com/ice3x2/win_ps.git
cd win_ps
msbuild win_ps.sln /p:Configuration=Release /p:Platform=x64

Binary will be generated at x64\Release\win_ps.exe.


πŸš€ Quick Start

Basic Usage

# List all processes (default output)
win_ps

# Full format with command line
win_ps -ef

# Long format with CPU and priority
win_ps -l

Example Output

# Default: win_ps
     PID    TIME	NAME
    2312   28:57	explorer.exe
    1234   00:15	chrome.exe
    5678   00:05	notepad.exe

# Full format: win_ps -ef
     PID    TIME    PPID     STIME	NAME			CMD
    2312   28:57    3536     07:58	explorer.exe	C:\WINDOWS\Explorer.EXE
    1234   00:15    4567     09:30	chrome.exe		"C:\Program Files\Google\Chrome\..."
    5678   00:05    1234     09:45	notepad.exe		"C:\WINDOWS\system32\notepad.exe"

πŸ“– Command Reference

Options

Option Description Example
-A, -e Show all processes (default) ps -e
-f Full format (adds PPID, STIME, CMD) ps -f
-l Long format (adds PPID, C, PRI) ps -l
-u USER Filter by username ps -u Administrator
-p PID Filter by process ID ps -p 1234
-C NAME Filter by executable name ps -C chrome.exe
-o FIELDS Select output columns ps -o pid,name,time
--sort FIELDS Sort by fields (prefix - for reverse) ps --sort -c,pid
--utf8 Force UTF-8 encoding ps --utf8 -f
--utf16 Force UTF-16 encoding ps --utf16 -f
-v, --version Show version ps -v
-h, --help Show help message ps --help

Output Fields

Field Description Example
pid Process ID 1234
ppid Parent Process ID 5678
user Username running the process Administrator
name Executable name chrome.exe
cmd Full command line "C:\Program Files\..."
time Cumulative CPU time (MM:SS) 02:30
c CPU usage percentage 5.2
pri Process priority 8
stime Start time (HH:MM) 09:30

πŸ’‘ Usage Examples

Filtering

# Find all Chrome processes
win_ps -C chrome.exe

# Show processes for specific user
win_ps -u Administrator

# Display specific process
win_ps -p 1234

Custom Output

# Show only PID, CPU, and name
win_ps -o pid,c,name

# Custom columns with sorting
win_ps -o pid,ppid,time,c,cmd --sort -c

Sorting

# Sort by CPU usage (descending)
win_ps --sort -c

# Multi-key sort: CPU descending, then PID ascending
win_ps --sort -c,pid

# Sort by CPU time
win_ps --sort -time

Combining Options

# Full format, filter by user, sort by CPU
win_ps -f -u beom --sort -c

# Long format, specific executable, custom columns
win_ps -l -C java.exe -o pid,c,pri,time,cmd

πŸ”€ Encoding Behavior

win_ps automatically detects the output destination and selects the optimal encoding:

Destination Encoding Purpose
Console UTF-16 Native Windows console support for Korean/CJK characters
Pipe UTF-8 Standard compatibility with Java, Python, Node.js, etc.
File UTF-8 Universal text file format

Why This Matters

Problem: Windows consoles use UTF-16, but most programming languages expect UTF-8 from pipes.

Solution: win_ps detects the output type using GetFileType() and adjusts encoding automatically.

Manual Override

Force a specific encoding when auto-detection doesn't work (rare cases like Git Bash):

# Force UTF-8 (for Java, Python, scripting)
win_ps --utf8 -f

# Force UTF-16 (for console compatibility)
win_ps --utf16 -f > output.txt

πŸ”— Integration Examples

Java

import java.io.*;
import java.nio.charset.StandardCharsets;

public class ProcessMonitor {
    public static void main(String[] args) throws Exception {
        ProcessBuilder pb = new ProcessBuilder("win_ps.exe", "-f");
        Process p = pb.start();

        // Auto-detects pipe β†’ outputs UTF-8
        BufferedReader reader = new BufferedReader(
            new InputStreamReader(p.getInputStream(), StandardCharsets.UTF_8)
        );

        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);  // Korean characters work perfectly
        }

        p.waitFor();
    }
}

Python

import subprocess

# Run win_ps and capture UTF-8 output
result = subprocess.run(
    ['win_ps.exe', '-f'],
    capture_output=True,
    text=True,
    encoding='utf-8'  # Auto-detects pipe β†’ UTF-8
)

for line in result.stdout.splitlines():
    print(line)

PowerShell

# Pipe to other commands
win_ps -f | Where-Object { $_ -match 'chrome' }

# Export to CSV (UTF-8)
win_ps -o pid,name,time,c | Out-File -Encoding UTF8 processes.txt

# Filter and sort
win_ps -f | Select-String 'java' | Sort-Object

Node.js

const { spawn } = require('child_process');

const ps = spawn('win_ps.exe', ['-f']);

ps.stdout.setEncoding('utf8');  // Auto-detects pipe β†’ UTF-8
ps.stdout.on('data', (data) => {
    console.log(data);
});

πŸ›  Advanced Usage

Monitoring CPU Usage

# Top 10 CPU consumers
win_ps -o pid,c,name --sort -c | head -n 11

# Processes using >5% CPU
win_ps -o pid,c,name | findstr /R "[5-9]\.[0-9]"

Finding Parent Processes

# Show process hierarchy
win_ps -o pid,ppid,name --sort ppid

# Find all children of PID 1234
win_ps -o pid,ppid,name | findstr "1234"

Automation Scripts

# Kill all Chrome processes
win_ps -C chrome.exe -o pid | ForEach-Object {
    if ($_ -match '^\s*(\d+)') {
        Stop-Process -Id $matches[1] -Force
    }
}

# Monitor specific process
while ($true) {
    Clear-Host
    win_ps -p 1234 -o pid,c,time,name
    Start-Sleep -Seconds 2
}

πŸ§ͺ Compatibility

Tested Platforms

  • βœ… Windows Server 2008 R2
  • βœ… Windows 7
  • βœ… Windows 8/8.1
  • βœ… Windows 10
  • βœ… Windows 11
  • βœ… Windows Server 2012/2016/2019/2022

Known Limitations

  • No elevated privileges needed, but some process details may be restricted for protected processes
  • CPU percentage is calculated over 1-second interval (not real-time)
  • Command line may be truncated for very long arguments (system limitation)

πŸ”§ Troubleshooting

Encoding Issues

Problem: Characters appear garbled in Java/Python

Solution: Ensure you're reading UTF-8 from the pipe:

new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)

Problem: Console output shows weird spacing

Solution: This is normal for UTF-16 detection. Redirect to file for UTF-8:

win_ps -f > output.txt  # Auto-detects file β†’ UTF-8

Performance

Problem: Slow on first run

Solution: Windows caches process information after first query. Subsequent runs are faster.

Missing Processes

Problem: Some processes don't appear

Solution: Protected system processes require SYSTEM privileges. win_ps shows all user-accessible processes.


πŸ“ License

MIT License - see LICENSE.txt for details.


πŸ™ Credits

  • Developer: @ice3x2
  • Initial Design Support: ChatGPT (OpenAI)
  • Encoding Implementation: Claude Sonnet 4.5 (Anthropic)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

⭐ Support

If this tool helps you, please consider giving it a star on GitHub!


Why win_ps?

  • GNU-compatible syntax (unlike tasklist)
  • No admin required (unlike pslist)
  • Smart encoding for modern development workflows
  • Lightweight and portable (single executable)

About

A Linux-style `ps` command for Windows.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages