port-process
ポート使用状況の確認や不要なプロセスの終了、システムリソース管理を効率的に行うSkill。
📜 元の英語説明(参考)
Find what's using a port, kill stuck processes, and manage system resources. Use when user mentions "port in use", "what's on port", "kill process", "lsof", "address already in use", "EADDRINUSE", "zombie process", "process management", "find PID", "free up port", "htop", "resource usage", or debugging port/process issues.
🇯🇵 日本人クリエイター向け解説
ポート使用状況の確認や不要なプロセスの終了、システムリソース管理を効率的に行うSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o port-process.zip https://jpskill.com/download/6117.zip && unzip -o port-process.zip && rm port-process.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/6117.zip -OutFile "$d\port-process.zip"; Expand-Archive "$d\port-process.zip" -DestinationPath $d -Force; ri "$d\port-process.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
port-process.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
port-processフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
[スキル名] port-process
ポートとプロセスの管理
ポートを使用しているものを探す
# macOS および Linux
lsof -i :3000
# Linux のみ (高速)
ss -tlnp | grep :3000
# 古い Linux システム
netstat -tlnp | grep :3000
# すべてのリッスンポートを表示
lsof -i -P -n | grep LISTEN
ss -tlnp
lsof -i :PORT は macOS と Linux の両方で動作し、最も信頼できる最初の選択肢です。Linux では、ss の方が高速で、非推奨の netstat よりも推奨されます。
プロセスを強制終了する
# PID で
kill 12345 # SIGTERM (正常終了)
kill -9 12345 # SIGKILL (強制終了、最終手段)
# ポートで — ポート 3000 を使用しているものを強制終了
lsof -ti :3000 | xargs kill
lsof -ti :3000 | xargs kill -9 # 強制
# 名前で
pkill node
pkill -f "next dev"
killall node # macOS/Linux、正確な名前で一致するすべてを強制終了
lsof -ti の -t フラグは PID のみを出力するため、kill にパイプで渡すことができます。
macOS と Linux の違い
| タスク | macOS | Linux |
|---|---|---|
| ポート検索 | lsof -i :PORT |
lsof -i :PORT または ss -tlnp |
| ポートによる強制終了 | lsof -ti :PORT \| xargs kill |
fuser -k PORT/tcp |
| プロセスツリー | pstree PID (brew 経由でインストール) |
pstree -p PID または ps --forest |
| ネットワーク統計 | netstat -an (-p フラグなし) |
ss -tlnp または netstat -tlnp |
| ファイルディスクリプタ | lsof -p PID |
ls /proc/PID/fd または lsof -p PID |
macOS では、ss と fuser は利用できません。lsof を使用してください。
「アドレスが既に使用されています」診断フロー
EADDRINUSE または「address already in use」が発生した場合:
# 1. ポートを所有しているものを探す
lsof -i :3000
# 2. それが自分の古いプロセスかどうかを確認する
lsof -i :3000 -sTCP:LISTEN
# 3. PID の詳細を取得する
ps -p <PID> -o pid,ppid,user,command
# 4. まずは正常終了を試みる
kill <PID>
# 5. 解放されたことを確認する
lsof -i :3000
# 6. まだ詰まっている場合は、強制終了する
kill -9 <PID>
# 7. ポートが TIME_WAIT (Linux) の場合、再利用できます
# コードに SO_REUSEADDR を追加するか、約 60 秒待つ
ss -tlnp | grep :3000
ポートが PPID 1 のプロセスによって保持されている場合、それは孤立したプロセスです。直接強制終了してください。
名前でプロセスを探す
# 実行中のプロセスを検索
ps aux | grep node
ps aux | grep -v grep | grep node # grep 自体を除外
# より良い代替手段
pgrep -la node # PID とコマンドラインをリスト
pgrep -f "next dev" # 完全なコマンド文字列に一致
pidof node # Linux のみ、PID を返す
# 既知の PID の詳細情報
ps -p 12345 -o pid,ppid,user,%cpu,%mem,etime,command
プロセスツリー
# Linux
pstree -p 12345 # PID をルートとするツリーを表示
ps -ejH # すべてのプロセスのツリービュー
ps --forest -eo pid,ppid,cmd
# macOS (pstree をインストールするには: brew install pstree)
pstree 12345
# プロセスの親を見つける
ps -o ppid= -p 12345
暴走したプロセスを生成したシェルやスーパーバイザーを見つけるのに役立ちます。
バックグラウンドとフォアグラウンド
# バックグラウンドで実行
node server.js &
# 現在のシェルでバックグラウンドジョブをリスト
jobs
# ジョブ #1 をフォアグラウンドに持ってくる
fg %1
# フォアグラウンドジョブをバックグラウンドに送る
# まず Ctrl-Z を押して (一時停止)、その後:
bg %1
# ターミナルから切り離す (ログアウト後も存続)
nohup node server.js > output.log 2>&1 &
# 既に実行中のバックグラウンドジョブを切り離す
node server.js &
disown %1
# disown はシェルにジョブを忘れさせるため、終了時に SIGHUP を受け取りません
リソース使用量
# 対話型プロセスモニター
top # どこでも組み込み
htop # より良い UI (別途インストール)
# ワンショット: CPU 使用率の高いプロセス (上位 20)
ps aux --sort=-%cpu | head -20 # Linux
ps aux -r | head -20 # macOS (CPU でソート)
# ワンショット: メモリ使用量の多いプロセス (上位 20)
ps aux --sort=-%mem | head -20 # Linux
ps aux -m | head -20 # macOS (メモリでソート)
# メモリの概要
free -h # Linux のみ
vm_stat # macOS (ページ数、バイト数にするには 4096 で割る)
ディスク使用量
# ファイルシステムの概要
df -h
# ディレクトリのサイズ
du -sh /path/to/dir
# 大きいディレクトリを探す (上位 10)
du -h /path | sort -rh | head -10
# 対話型ディスク使用量エクスプローラー
ncdu /path # 別途インストール、非常に便利
# 100MB を超えるファイルを探す
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null
# Docker ディスク使用量 (一般的なスペースの占有者)
docker system df
docker system prune -a # スペースを再利用、未使用のイメージ/コンテナを削除
ファイルディスクリプタ
# 現在の制限を確認
ulimit -n # オープンファイルのソフトリミット
ulimit -Hn # ハードリミット
# 現在のセッションのソフトリミットを上げる
ulimit -n 65536
# プロセスのオープンファイルをリスト
lsof -p 12345
lsof -p 12345 | wc -l # 数をカウント
# Linux: 直接検査
ls /proc/12345/fd | wc -l
# 多くのオープンファイルを持つプロセスを探す (Linux)
for pid in /proc/[0-9]*; do
echo "$(ls $pid/fd 2>/dev/null | wc -l) $pid"
done | sort -rn | head -10
プロセスがファイルディスクリプタの制限に達すると、「too many open files」のようなエラーがログに記録されます。ulimit -n を上げるか、ファイル/ソケットリークを修正してください。
シグナル
| シグナル | 番号 | 動作 | 使用するタイミング |
|---|---|---|---|
| SIGTERM | 15 | 正常終了、プロセスは捕捉してクリーンアップ可能 | デフォルト。常に最初に試す。 |
| SIGINT | 2 | Ctrl-C と同じ | 対話的な停止 |
| SIGHUP | 1 | ハングアップ。一部のデーモンは SIGHUP で設定をリロードする。 | 設定のリロード (nginx, Apache) |
| SIGKILL | 9 | 即時終了、捕捉不可 | プロセスが SIGTERM を無視する場合 |
| SIGSTOP | 19 | プロセスを一時停止 (Ctrl-Z のように) | プロセスを一時的にフリーズさせる |
| SIGCONT | 18 | 停止したプロセスを再開 | SIGSTOP 後に再開 |
常に最初に SIGTERM を送信してください。数秒間待ってください。プロセスが終了を拒否する場合にのみ SIGKILL (kill -9) を使用してください。SIGKILL はすべてのクリーンアップをスキップします — 一時ファイル、ロックファイル、ソケットが残されます。
kill PID # SIGTERM
kill -HUP PID # SIGHUP (リロード)
kill -9 PID # SIGKILL (最終手段)
一般的なシナリオ
開発サーバーが起動しない (ポートが使用中)
lsof -ti :3000 | xargs kill
# その後、サーバーを再起動します
孤立した Node.js プロセスが CPU を消費している
pgrep -la node
# 古いものを特定します 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Port and Process Management
Find What's Using a Port
# macOS and Linux
lsof -i :3000
# Linux only (faster)
ss -tlnp | grep :3000
# Older Linux systems
netstat -tlnp | grep :3000
# Show all listening ports
lsof -i -P -n | grep LISTEN
ss -tlnp
lsof -i :PORT works on both macOS and Linux and is the most reliable first choice. On Linux, ss is faster and preferred over the deprecated netstat.
Kill a Process
# By PID
kill 12345 # SIGTERM (graceful)
kill -9 12345 # SIGKILL (forced, last resort)
# By port — kill whatever is on port 3000
lsof -ti :3000 | xargs kill
lsof -ti :3000 | xargs kill -9 # forced
# By name
pkill node
pkill -f "next dev"
killall node # macOS/Linux, kills all matching by exact name
The -t flag in lsof -ti outputs only PIDs, making it pipeable to kill.
macOS vs Linux Differences
| Task | macOS | Linux |
|---|---|---|
| Port lookup | lsof -i :PORT |
lsof -i :PORT or ss -tlnp |
| Kill by port | lsof -ti :PORT \| xargs kill |
fuser -k PORT/tcp |
| Process tree | pstree PID (install via brew) |
pstree -p PID or ps --forest |
| Network stats | netstat -an (no -p flag) |
ss -tlnp or netstat -tlnp |
| File descriptors | lsof -p PID |
ls /proc/PID/fd or lsof -p PID |
On macOS, ss and fuser are not available. Stick with lsof.
"Address Already in Use" Diagnostic Flow
When you hit EADDRINUSE or "address already in use":
# 1. Find what owns the port
lsof -i :3000
# 2. Check if it's your own stale process
lsof -i :3000 -sTCP:LISTEN
# 3. Get details on the PID
ps -p <PID> -o pid,ppid,user,command
# 4. Graceful kill first
kill <PID>
# 5. Verify it released
lsof -i :3000
# 6. If still stuck, force kill
kill -9 <PID>
# 7. If port is in TIME_WAIT (Linux), you can reuse it
# Add SO_REUSEADDR in code, or wait ~60 seconds
ss -tlnp | grep :3000
If the port is held by a process with PPID 1, it is orphaned. Kill it directly.
Find Processes by Name
# Search running processes
ps aux | grep node
ps aux | grep -v grep | grep node # exclude the grep itself
# Better alternatives
pgrep -la node # list PIDs and command lines
pgrep -f "next dev" # match full command string
pidof node # Linux only, returns PIDs
# Detailed info for a known PID
ps -p 12345 -o pid,ppid,user,%cpu,%mem,etime,command
Process Tree
# Linux
pstree -p 12345 # show tree rooted at PID
ps -ejH # tree view of all processes
ps --forest -eo pid,ppid,cmd
# macOS (install pstree via: brew install pstree)
pstree 12345
# Find parent of a process
ps -o ppid= -p 12345
Useful for finding which shell or supervisor spawned a runaway process.
Background and Foreground
# Run in background
node server.js &
# List background jobs in current shell
jobs
# Bring job #1 to foreground
fg %1
# Send foreground job to background
# Press Ctrl-Z first (suspends it), then:
bg %1
# Detach from terminal (survives logout)
nohup node server.js > output.log 2>&1 &
# Disown an already-running background job
node server.js &
disown %1
# disown makes the shell forget about the job so it won't get SIGHUP on exit
Resource Usage
# Interactive process monitor
top # built-in everywhere
htop # better UI (install separately)
# One-shot: top processes by CPU
ps aux --sort=-%cpu | head -20 # Linux
ps aux -r | head -20 # macOS (sorted by CPU)
# One-shot: top processes by memory
ps aux --sort=-%mem | head -20 # Linux
ps aux -m | head -20 # macOS (sorted by memory)
# Memory summary
free -h # Linux only
vm_stat # macOS (pages, divide by 4096 for bytes)
Disk Usage
# Filesystem overview
df -h
# Size of a directory
du -sh /path/to/dir
# Find large directories (top 10)
du -h /path | sort -rh | head -10
# Interactive disk usage explorer
ncdu /path # install separately, very useful
# Find files over 100MB
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null
# Docker disk usage (common space hog)
docker system df
docker system prune -a # reclaim space, removes unused images/containers
File Descriptors
# Check current limits
ulimit -n # soft limit for open files
ulimit -Hn # hard limit
# Raise soft limit for current session
ulimit -n 65536
# List open files for a process
lsof -p 12345
lsof -p 12345 | wc -l # count them
# Linux: inspect directly
ls /proc/12345/fd | wc -l
# Find processes with many open files (Linux)
for pid in /proc/[0-9]*; do
echo "$(ls $pid/fd 2>/dev/null | wc -l) $pid"
done | sort -rn | head -10
If a process hits the file descriptor limit, it logs errors like "too many open files." Raise ulimit -n or fix the file/socket leak.
Signals
| Signal | Number | Behavior | When to use |
|---|---|---|---|
| SIGTERM | 15 | Graceful shutdown, process can catch and clean up | Default. Always try first. |
| SIGINT | 2 | Same as Ctrl-C | Interactive stop |
| SIGHUP | 1 | Hangup. Some daemons reload config on SIGHUP. | Reload config (nginx, Apache) |
| SIGKILL | 9 | Immediate termination, cannot be caught | Process ignores SIGTERM |
| SIGSTOP | 19 | Pause process (like Ctrl-Z) | Temporarily freeze a process |
| SIGCONT | 18 | Resume stopped process | Unpause after SIGSTOP |
Always send SIGTERM first. Give it a few seconds. Only use SIGKILL (kill -9) when the process refuses to exit. SIGKILL skips all cleanup -- temp files, lock files, and sockets will be left behind.
kill PID # SIGTERM
kill -HUP PID # SIGHUP (reload)
kill -9 PID # SIGKILL (last resort)
Common Scenarios
Dev server won't start (port taken)
lsof -ti :3000 | xargs kill
# then restart your server
Orphaned Node.js process eating CPU
pgrep -la node
# identify the stale one by its command line
kill <PID>
Multiple stale dev servers
# Kill all node processes (careful in production)
pkill -f "next dev"
pkill -f "vite"
pkill -f "react-scripts"
Out of disk space
df -h # confirm which volume is full
du -h /home --max-depth=2 | sort -rh | head -20 # find biggest dirs
# Common culprits:
docker system prune -a # unused Docker data
rm -rf node_modules/.cache # build caches
npm cache clean --force # npm cache
Zombie processes
# Find zombies
ps aux | awk '$8=="Z"'
# Zombies can't be killed directly -- kill their parent instead
ps -o ppid= -p <ZOMBIE_PID>
kill <PARENT_PID>
A zombie is a process that finished but whose parent hasn't read its exit status. Killing the parent lets init/systemd reap it.