Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 9, 2025

Summary

Resolves #18 by adding comprehensive documentation and examples for accessing process IDs (PIDs) of started commands.

Changes Made

📁 New Files

  • examples/process-pid-access.mjs - Complete example file with 7 different scenarios demonstrating PID access

📚 Documentation Updates

  • README.md - Added new "Process ID (PID) Access" section with practical examples and best practices
  • README.md - Updated API reference to document command.child.pid property
  • examples/README.md - Added Process Management section and usage examples

Key Features Demonstrated

Multiple Access Methods:

  • Via command.streams.stdout (recommended)
  • Via command.start()
  • Via command.stream() for streaming

Comprehensive Examples:

  1. Basic PID access with auto-start via streams
  2. PID access with explicit start
  3. Multiple commands PID tracking
  4. PID access with streaming
  5. Event-based processing with PID
  6. PID availability timeline
  7. Error handling and best practices

Best Practices:

  • Safe PID access with error handling
  • Understanding PID availability lifecycle
  • Proper process initialization
  • Documentation of edge cases with fast commands

Example Usage

import { $ } from 'command-stream';

// Method 1: Access PID after starting via streams (recommended)
const command = $`ping -c 5 google.com`;
const stdout = await command.streams.stdout;

if (command.child && command.child.pid) {
  console.log(`Command PID: ${command.child.pid}`);
}

Testing

  • ✅ Example file is executable and runs successfully
  • ✅ Demonstrates all documented methods work correctly
  • ✅ Shows proper error handling for edge cases
  • ✅ Includes educational output explaining when PIDs are/aren't available

Files Changed

  • examples/process-pid-access.mjs (new)
  • README.md
  • examples/README.md

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #18
@konard konard self-assigned this Sep 9, 2025
konard and others added 2 commits September 9, 2025 22:53
- Add process-pid-access.mjs example demonstrating 7 different ways to access PIDs
- Update README.md with Process ID access section in main documentation
- Update examples/README.md with process management section
- Document command.child.pid property in API reference
- Show best practices for safe PID access and error handling
- Cover all three methods to start processes and access PIDs

Resolves #18 - provides clear examples and documentation on how to get
PID of started commands.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] We need example in docs on how to get PID of started command Add comprehensive PID access documentation and examples Sep 9, 2025
@konard konard marked this pull request as ready for review September 9, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

We need example in docs on how to get PID of started command

2 participants