tracking another process and detecting it open a new file
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
tracking another process and detecting it open a new file
process A running my code (in Python unless i need to use C) starts process B (in a directory process A created) which execs some other binary executable. process B opens a file for output in the current directory that will always be a new file. i want to have process A learn about this event and learn the name of that file ASAP. is there a better way to do this than repeatedly getting the change time of this directory, detecting a change, and getting a list of file names to see what's new? my intent is to watch the growth of this file, looking for a period of no growth or the exit of process B. process A will kill process B if this pause is detected and start another instance and track that one. each time a file is complete, it will be moved to another directory where another process archives it (and all the other instances of A/B pairs that will run concurrently). the various pairs will be downloading different information (what program B does for just one case). the problem i am having is that process B stalls frequently. i am trying to work around that. i will need to work good timing values.
process A stays running my Python code. however, process B execs a binary i did not develop. i might be able to get its source code and mod it to send notification. can inotify just do this on its own based on the system calls the tracked process performs? i do intend to run a separate process A for each of these cases so i do not need to make process A do multithreading so there will be as many process As as there are separate cases. so if inotify cannot do complex multi-waiting for all the various cases, that's OK. i'll go try to find it after this posts.
looks like process B will need to be written in Python to do this. but it comes in binary. specifically, the program to run in process B is "ffmpeg" being given the URL of a video to download. it uses the file name given by the server and my process A code does not know what that name is. once it is aware the file is started, it will rescan the names in the directory to see what is new (it is probably the only file). i just want a faster way to know the file has been created rather that doing lstat() on the directory every 1/4 second.
looks like process B will need to be written in Python to do this.
Say what ?.
Quote:
i just want a faster way to know the file has been created rather that doing lstat() on the directory every 1/4 second.
Go back and read the inotify doco then. You set a watch on the target directory and wait to be told what has just happened. No-one cares what the perpetrator is - the kernel will see the event and tell you.
i was expecting the watched app to send the notification. i thought of Python because that's what i have been doing things with. i was thinking about a different notification tool.
Quote:
Originally Posted by syg00
Go back and read the inotify doco then. You set a watch on the target directory and wait to be told what has just happened. No-one cares what the perpetrator is - the kernel will see the event and tell you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.