Monitoring active processes ...

Hi,

Still trying to understand how to monitor my computer’s activity …

When the backup application Carbon Copy Cloner (CCC) is running, a few processes are triggered: 2 or 3 «rsync» and also «ccc_helper». With this statement:

tell application "System Events" to exists process "theAppsName"

I can check if the process «ccc_helper» exists but I cannot with «rsync» even if it is running. Both processes belong to Root. What is the difference between these 2 processes ? I would like to check (with AppleScript or shellscript) if «rsync» is running. How can I do that ?

Maybe code as follows is sufficient?


if my processisactive("rsync") then
	tell me
		display dialog "rsnyc is active!"
	end tell
end if

on processisactive(processname)
	set command to "ps -c -A | grep " & quoted form of processname
	try
		set output to do shell script command
		return true
	on error
		return false
	end try
end processisactive

Bonjour Martin,

Great it works … Thanks !

Can you explain me what exactly the shellscript does ? Does it detect a process that is open (0% CPU usage) or using CPU ? Does it apply to applications also ?

Thanks in advance.

Robert Lespérance

Hallo Robert,

As I am currently quite busy, just type:

man ps

into an open terminal window.

And yes, it also lists apps.

Still very confused. Like the first chinese lessons :lol::lol::lol::lol: If you have time later to answer my questions, I would appreciate.

Funny … I tried your script on «rsync» and when executing the script displayed the message. I tried it on «Retrospect» that is a root application (I have been trying to monitor it for a long time without success). The script never displayed the message either when active and not executing nor when executing.

Regards.

For root processes only you can also try to use this modified code:


if my processisactive("rsync") then
   tell me
       display dialog "rsnyc is active!"
   end tell
end if

on processisactive(processname)
   set command to "ps -c -u root | grep " & quoted form of processname
   try
       set output to do shell script command
       return true
   on error
       return false
   end try
end processisactive

Hi Martin,

I am trying to see how I can better monitor the idle, running/executing and done state of any root process. I have 2 of these processes I am working with. One is used by SuperDuper: “SDCopy” runs when SD is currently executing a backup. The other is the “Retrospect” application. While these processes both run under Root, the result of your 2 scripts differ.

¢ SDCopy returns true to the first script and false to the second
¢ Retrospect returns false to both

What is the state that your scripts are supposed to return and why is the reply different ? What does each of your script exactly do ?

Regards.

Robert Lespérance


Script 1. set command to "ps -c -A | grep " & quoted form of theProcess
Script 2. set command to "ps -c -u root | grep " & quoted form of theProcess

Model: iMac G5 - 1.6 mgz
AppleScript: 2.1.1
Browser: Safari 525.18
Operating System: Mac OS X (10.4)