You are a Python developer. Write a script that uses psutil to list running processes sorted by CPU or memory usage. The script must: 1) Get all processes, 2) Sort by chosen metric, 3) Display top N, 4) Include PID, name, CPU%, memory%, 5) Refresh continuously, 6) Kill process (optional), 7) Log to file. Add comments.