LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 05-21-2024, 06:08 PM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,694
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
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.
 
Old 05-21-2024, 09:19 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,161

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
inotify - seems to be python bindings.
 
Old 05-27-2024, 08:24 PM   #3
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,694

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
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.
 
Old 06-01-2024, 10:41 PM   #4
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,694

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
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.
 
Old 06-02-2024, 05:27 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,383
Blog Entries: 3

Rep: Reputation: 3774Reputation: 3774Reputation: 3774Reputation: 3774Reputation: 3774Reputation: 3774Reputation: 3774Reputation: 3774Reputation: 3774Reputation: 3774Reputation: 3774
Quote:
Originally Posted by Skaperen View Post
i just want a faster way to know the file has been created rather that doing lstat() on the directory every 1/4 second.
You can do that with incron and have it trigger a script when new files are created in a specific directory.

Edit: As per the next comment:
https://linux.die.net/man/5/incrontab
https://linux.die.net/man/1/incrontab

Last edited by Turbocapitalist; 06-02-2024 at 06:16 AM.
 
Old 06-02-2024, 06:13 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,161

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Quote:
Originally Posted by Skaperen View Post
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.
 
Old 06-09-2024, 01:13 PM   #7
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,694

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by syg00 View Post
Say what ?.
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 View Post
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.
OK. looks like the right way to do this. thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] SSH login tracking and session activity Tracking Veen77 Linux - Security 9 09-04-2019 09:11 AM
@FedEx Tracking: pasting correct tracking # causes error; typing same works mike3644 Linux - Software 7 02-15-2018 03:55 PM
USB devices stop detecting (or un-detecting). Mleahy Linux - Desktop 1 07-31-2011 02:08 AM
RedHat 9 is not detecting the LAN card, but Win'98 is detecting the LAN card SKYNAT Linux - Newbie 4 12-28-2007 10:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration