将运行进程扩展到ubuntu

问题描述 投票:0回答:1

您可以从Ubuntu的终端中使用BASH脚本。如果将脚本保存为文件名“ proc.sh”,请从命令行

bash proc.sh

linux ubuntu terminal
1个回答
0
投票
#!/bin/bash # Define output CSV file name OUTPUT_FILE="processes.csv" # Create/overwrite the file with headers echo "PID,USER,CPU%,MEM%,VSZ,RSS,TTY,STAT,START,TIME,COMMAND" > $OUTPUT_FILE # Get process information and append to CSV file # We use ps aux and then replace spaces with commas using awk ps aux | tail -n +2 | awk '{ # Store the command (which might contain spaces) command = "" for (i=11; i<=NF; i++) { if (command != "") command = command " " command = command $i } # Replace any commas in the command with spaces to prevent CSV issues gsub(",", " ", command) # Print the data in CSV format printf "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,\"%s\"\n", $2, $1, $3, $4, $5, $6, $7, $8, $9, $10, command }' >> $OUTPUT_FILE echo "Process information has been written to $OUTPUT_FILE"

	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.