how to know that a perticular process is started!!!

Hi all,

I wanted a write a script which will start executing whenever a particular process will starts running in a background.
Is there is any way in Unix if a directory contents changed then a signal/Interrupt will generated and by taking status of that interrupt I can execute some scripts.
Please provide your ideas and solution if any...

Thanks...

More recent Linux kernels provide change-notify information for directories.

What platform/OS?

>What platform/OS?

HP-UX B.11.11

I think we can do this simply by keeping our eye on the Process Status table, where particular process id is generated for the processes.
By that we can check the parent or child process has been started or not and accordingly we can react on that.
Each process has a process id, its status (R/Z/O/S), and name of the process.
I think this idea will work, but ofcourse we have to monitor the ps table closely.

Thanks

>I think we can do this simply by keeping our eye on the Process Status table, where particular process id is generated for the processes.

Yes this can be a solution that I thought, but this is not a efficient way to run a program continuously to see the status of other required process.
I want a interrupt/signaling mechanism which will trigger my script when a particular process get started.

Is there any way to see the process execution log so at least I can poll after a specific interval of time to that log and if I see the process is being executing or recently executed then I will trigger my script.

Thanks...

Or why not go for a quick simple solution?

Aim: to run program B whenever program A is started....

Rename A to A.orig

create a file called A as follows...

#!/bin/sh
B $$ </dev/null 1>/dev/null 2>&1 &
exec A.orig $@

It will even give you the pid of the program as an argument.

#!/bin/sh
B $$ >/dev/null 1>/dev/null 2>&1 &
exec A.orig $@

It will even give you the pid of the program as an argument.
[/quote]

------------------------------------------------------------------------

what does the second line does here....can you explain.

thx
bishweshwar

the first line says this is a script to be run by /bin/sh

the second line says spawn program B but attach stdin, stdout and stderr to /dev/null so they don't affect the output of the current process, this process will spin off on it's merry way due to the "&", the "$$" will be replaced by the current process id. this is the program that says "A" is running and allows you to do your funky custom stuff here.

the third line says run the original program using the original arguments in this process so the process-id we gave out in line two is still the correct one.

When "$$" is replaced by the shell id....is it passed as an argument to process B.

Clever. I like it.

How about checking and using the access time of the binary provided in /etc/fstab noatime is not set !!! :slight_smile:

That wouldn't be much better than some of ther other options. You would still end up polling the file to check for a change.