Vai al contenuto


USI TWITTER? Allora devi assolutamente seguire @tevac e non puoi perderti @lo_ziopino!

Foto

Durata di esecuzione di un programma

trucchi

  • Per cortesia connettiti per rispondere
Nessuna risposta a questa discussione

#1 Signor D

Signor D

    Melina al Valore

  • Forum Staff
  • 7693 messaggi
  • Sesso:Maschietto
  • Località:Parigi

Inviato 30 novembre 2012 - 15:51

Trovato su http://hints.macworl...121127064752309

I wanted to find out how long a certain background process had been running. There's a column for CPU Time in Activity Monitor, but that's not real clock time.

It turns out you can get this information with ps, via the etime keyword. So to get a list of every running process, in decreasing order of run time, just use this command:

ps -ax -o etime,command -c

To see the results for a single process, just add a grep at the end for the process' name. For example:

$ ps -ax -o etime,command -c | grep AppleVNCServer
03-08:09:16 AppleVNCServer

So on my Mac, the AppleVNCServer has been running for three days, eight hours, nine minutes, and 16 seconds. I have a need to do this pretty regularly, so I turned it into a simple command line app:

#!/bin/bash

# Display the time a given process has been running
# Use the process name when calling the command

ps -ax -o etime,command -c | grep $1

I saved that to a file named psup, and made it executable with chmod 755 psup. Now I can just type psup SomeProcess to see the uptime for SomeProcess.


D