Script to monitor a process and track status in a file

i have a scenario where i need a script that monitors a process "Monitor" based on process id... there can be any number of instances of this running... i start this across 4 servers in NFS. Now i need a file which has the process ids of the process that are currently in execution at any instant,this script must also remove an entry of a process as an when that process completes.

What are things you want to monitor ? Is it only the status that process running or not or anything else.

status and memory utilization.....

First you need to capture the PID when every the process-to-be-monitored is started. This can be done either using a startup script to start the process and add the PID in to a file or directly from your process to write its own PID.

Once this is captured you can write shell script that periodically checks for the status of the processes and their memory utilization. say every 1 mins or 2 mins. If the PID exists but for a different process then remove the PID.

Note this idea has to refined to your needs.

i could do till adding of process ids....the problem is deletion should happen after monitoring across NFS connected servers where im not able to proceed....

I don't understand the point "NFS connected servers". Is it like NFS clients that are running the processes and you want NFS server to monitor the process status.

just to say that all servers share file system thats it....i tried with ssh but its taking a long time to update...

Then I don't think shell script suits your need. If you are planning for a single file to store your PIDs in the shared file system, you will also need the host name on which this PID is present.

Then you may use python network utilities. You have to host a process in each of this servers and that will reply your queries about the PID. This process must be queried with the PID and will return the status and memory utilization if it is running.

We have constraint either to use shell scripts or perl script....i do not know python..

I think you can also use perl as it supports network programming. But i haven't tried.