Sponsored Content
Top Forums UNIX for Advanced & Expert Users Last touched file by a specific program ? Post 302926319 by derekludwig on Sunday 23rd of November 2014 09:35:55 AM
Old 11-23-2014
With respect to RudiC, use of a file's access time can be problematic if any other process reads the file, such as backups.

Why 3 programs? Are they three instances of the same program?

If the expense of starting a new process is not onerous, perhaps it would be easier just to use a dispatcher that launches no more than N of your programs:

(pseudo shell code!)
Code:
filescanner | while read file; do
  while [[ ${N} -le $(pgrep appropriateoptions | wc -l) ]]; sleep ${time}; done
  fileomatic ${file} &
done

Or the dispatcher could write a file to one of N named-pipes, one for each fileomatic, something like:

(more pseudo shell code)
Code:
work=$(mktemp -d)

N=0

while read fileomatic; do
  (( N = N + 1 ))
  pipe=${work}/pipe.${N}
  ready=${work}/ready.${N}

  mkfifo ${pipe}

  ${fileomatic} ${ready} < ${pipe} &
done 

filescanner | while read file; do

  while sleep ${delay}; do

    ls -1 ${work}/*.ready | read -aready

    if [[ 0 -lt ${#ready[*]} ]]; then
      i=$(( ${RANDOM} % ${#ready[*]} ))
      n=${ready[$i]}
      echo "${file}" >> ${work}/pipe.${n##*.}
      break
    fi

  done

done

The idea is that the fileomatic will touch the 'ready' file when it can process a file

Last edited by derekludwig; 11-27-2014 at 02:59 PM.. Reason: Typo in arithmantic expression, and some bad logic
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Which Base Level Filesets needed by a specific program?

hello... thats a great forum btw :) my problem is that I need a list of the Base Level Filesets (BLF) which are needed by a specific program. Is there any command/tool which shows me that? during the installation I can choose "Preview only" so that I can see what BLF´s are missing etc but... (4 Replies)
Discussion started by: cypher82
4 Replies

2. UNIX for Dummies Questions & Answers

comparing timestamp of a file with its touched version

Hi, I'm new to unix,I wanna know how can I compare timestamp of a file with its touched version.i.e I want to be sure if the touch command has worked properly i.e if the file has been touched then a msg should be printed saying success else failure.All this to be incurred in a script. Any... (2 Replies)
Discussion started by: prince258
2 Replies

3. UNIX for Advanced & Expert Users

Checking mem usage at specific times in a program

Hi all, I'm running a simulator and I'm noticing an slow increase in memory for long simulations such that the simulation has to end because of a lack of memory. A colleague of mine ran Valgrind memcheck and reported that nothing of interest was reported other than known mem leaks. My advisor... (2 Replies)
Discussion started by: pl4u
2 Replies

4. What is on Your Mind?

Finally I touched 1000.Yahooooo!!!

This, my venerable audience, is my 1000th post here. Thanks for your support and help..:b: ---Vidyadhar:) (4 Replies)
Discussion started by: vidyadhar85
4 Replies

5. UNIX for Dummies Questions & Answers

Never touched UNIX before.. Where do I start?

I will be taking a UNIX course as a part of my college Data Com concentration curriculum. Just thought it would be a good idea to get a little head start, since this class will most likely be quite difficult for someone like me. I never did any programming and I never dealt with Unix or Linux short... (3 Replies)
Discussion started by: ibex333
3 Replies

6. AIX

how to find which program that update a specific file

Hello Would you tell me how to find which program that update a specific file? I am implementing migration project. My machines OS are AIX. It is because lack of documentation, some program cannot working properly on new machine. We found the root cause of this problem is that some data... (4 Replies)
Discussion started by: cstsang
4 Replies

7. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

8. Shell Programming and Scripting

Program to search for the files with specific format

Hi All, Your help on the below requirement is highly appreciated. I am building a program which should pick the file from a source directory and place them into target directory. While selecting the file in source it should look for some pattern in the file name. Ex: File Name 1:... (10 Replies)
Discussion started by: bharath561989
10 Replies

9. Shell Programming and Scripting

Running program and output files in specific directories

I have been running a program mseed2sac using the following command cd IV find . -type f -exec /swadmin/mseed2sac '{}' \; The problem is that I end up with a lot of files in directory IV. Instead I would like to select the designator HHZ, create a directory IV.SAC and all the files output... (11 Replies)
Discussion started by: kristinu
11 Replies

10. UNIX for Beginners Questions & Answers

Seraching for a specific program

I know that Qt exists on this IMX6+ the device has Linux 4.9.184 embedded. I need to figure out which version of Qt it has. What is the best way to find a program given only a text based terminal? Is there a way I can grep for it? (2 Replies)
Discussion started by: Circuits
2 Replies
select(2)							System Calls Manual							 select(2)

NAME
select(), pselect(), FD_CLR(), FD_ISSET(), FD_SET(), FD_ZERO() - synchronous I/O multiplexing SYNOPSIS
For Backward Compatibility Only: (_XOPEN_SOURCE_EXTENDED not defined) DESCRIPTION
The and functions indicate which of the specified file descriptors is ready for reading, ready for writing, or has an error condition pend- ing. If the specified condition is false for all of the specified file descriptors, and block, up to the specified timeout interval, until the specified condition is true for at least one of the specified file descriptors. The and functions support regular files, terminal and pseudo-terminal devices, STREAMS-based files, FIFOs and pipes. The behaviour of and on file descriptors that refer to other file types is unspecified. The nfds argument specifies the range of file descriptors to be tested. The and functions test file descriptors in the range of 0 to nfds -1. File descriptor f is represented by the bit 1<<f in the masks. More formally, a file descriptor is represented by: If the readfds argument is not a null pointer, it points to an object of type fd_set that on input specifies the file descriptors to be checked for being ready to read, and on output indicates which file descriptors are ready to read. If the writefds argument is not a null pointer, it points to an object of type fd_set that on input specifies the file descriptors to be checked for being ready to write, and on output indicates which file descriptors are ready to write. If the errorfds argument is not a null pointer, it points to an object of type fd_set that on input specifies the file descriptors to be checked for error conditions pending, and on output indicates which file descriptors have error conditions pending. On successful completion, the objects pointed to by the readfds, writefds, and errorfds arguments are modified to indicate which file descriptors are ready for reading, ready for writing, or have an error condition pending, respectively. For each file descriptor less than nfds, the corresponding bit will be set on successful completion if it was set on input and the associated condition is true for that file descriptor. If the timeout argument is not a null pointer, it specifies a maximum interval to wait for the selection to complete. The timeout argument points to an object of type for and to an object of type for If the members of these structures are 0, or will not block. If the timeout argument is a null pointer, or will block until an event causes one of the masks to be returned with a valid (non-zero) value. If the time limit expires before any event occurs that would cause one of the masks to be set to a non-zero value, or completes successfully and returns 0. Implementations may place limitations on the maximum timeout interval supported. On all implementations, the maximum timeout interval sup- ported will be at least 31 days. If the timeout argument specifies a timeout interval greater than the implementation-dependent maximum value, the maximum value will be used as the actual timeout value. Implementations may also place limitations on the granularity of time- out intervals. If the requested timeout interval requires a finer granularity than the implementation supports, the actual timeout inter- val will be rounded up to the next supported value. If sigmask is not a null pointer, then the function shall replace the signal mask of the process by the set of signals pointed to by sig- mask before examining the descriptors, and shall restore the signal mask of the process before returning. If the readfds, writefds, and errorfds arguments are all null pointers and the timeout argument is not a null pointer, or blocks for the time specified, or until interrupted by a signal. If the readfds, writefds, and errorfds arguments are all null pointers and the timeout argument is a null pointer, or blocks until interrupted by a signal. File descriptors associated with regular files always select true for ready to read, ready to write, and error conditions. On failure, the objects pointed to by the readfds, writefds, and errorfds arguments are not modified. If the timeout interval expires without the specified condition being true for any of the specified file descriptors, the objects pointed to by the readfds, writefds, and errorfds arguments have all bits set to 0. Ttys and sockets are ready for reading if a would not block for one or more of the following reasons: o input data is available. o an error condition exists, such as a broken pipe, no carrier, or a lost connection. Similarly, ttys and sockets are ready for writing if a would not block for one or more of the following reasons: o output data can be accepted. o an error condition exists, such as a broken pipe, no carrier, or a lost connection. TCP sockets select true on reads only for normal data. They do not select true on reads if out-of-band data ("urgent" data) arrives. TCP sockets select true on exceptions for out-of-band data. AF_CCITT sockets select true on reads for normal and out-of-band data and information, including supervisory frames. Pipes are ready for reading if there is any data in the pipe, or if there are no writers left for the pipe. Pipes are ready for writing if there is room for more data in the pipe AND there are one or more readers for the pipe, OR there are no readers left for the pipe. returns the same results for a pipe whether a file descriptor associated with the read-only end or the write-only end of the pipe is used, since both file descriptors refer to the same underlying pipe. So a of a read-only file descriptor that is associated with a pipe can return ready to write, even though that particular file descriptor cannot be written to. File descriptor masks of type fd_set can be initialized and tested with and It is unspecified whether each of these is a macro or a func- tion. If a macro definition is suppressed in order to access an actual function, or a program defines an external identifier with any of these names, the behaviour is undefined. Clears the bit for the file descriptor fd in the file descriptor set fdset. Returns a non-zero value if the bit for the file descriptor fd is set in the file descriptor set pointed to by fdset, and 0 otherwise. Sets the bit for the file descriptor fd in the file descriptor set fdset. Initializes the file descriptor set fdset to have zero bits for all file descriptors. The behaviour of these macros is undefined if the fd argument is less than 0 or greater than or equal to The use of a timeout does not affect any pending timers set up by or On successful completion, the object pointed to by the timeout argument of may be modified. The is used in the definition of structure. It is set to a value of 2048 to accommodate 2048 file descriptors. Any user code that uses or the structure should redefine to a smaller value (greater than or equal to the number of open files the process will have) in order to save space and execution time. Similarly, any user code that wants to test more than 2048 file descriptors should redefine to the required higher value. The user can also allocate the space for structure dynamically, depending upon the number of file descriptors to be tested. The following code segment illustrates the basic concepts. RETURN VALUE
and return no value. returns a non-zero value if the bit for the file descriptor fd is set in the file descriptor set pointed to by fdset, and 0 otherwise. On successful completion, and return the total number of bits set in the bit masks. Otherwise, -1 is returned, and is set to indicate the error. ERRORS
Under the following conditions, and fail and set to: One or more of the file descriptor sets specified a file descriptor that is not a valid open file descriptor. This could happen either if the file descriptor sets are not initialized or nfds argument is greater than The function was interrupted before any of the selected events occurred and before the timeout interval expired. If has been set for the interrupting signal, it is imple- mentation-dependent whether the function restarts or returns with One or more of the pointers was invalid. The reliable detection of this error is implementation dependent. An invalid timeout interval was specified. Valid values for the number of nanoseconds (in should be a non-negative integer less than 1,000,000,000. For the number of microseconds (in struct timeval), a non-negative integer less than 1,000,000 should be used. Seconds should be specified using a non-negative integer. The nfds argument is less than 0, or is greater than or equal to the value of which specifies the absolute maximum number of files a process can have open at one time. If the resource limit for a process is less than or equal to 2048, is considered to be 2048. One of the specified file descriptors refers to a STREAM or multiplexer that is linked (directly or indirectly) downstream from a multiplexer. EXAMPLES
The following call to checks if any of 4 terminals are ready for reading. times out after 5 seconds if no terminals are ready for reading. Note that the code for opening the terminals or reading from the terminals is not shown in this example. Also, note that this example must be modified if the calling process has more than 32 file descriptors open. Following this first example is an example of select with more than 32 file descriptors. The following example is the same as the previous example, except that it works for more than 32 open files. Definitions for and are in WARNINGS
The file descriptor masks are always modified on return, even if the call returns as the result of a timeout. DEPENDENCIES
supports the following devices and file types: o pipes o fifo special files (named pipes) o all serial devices o All ITEs (internal terminal emulators) and HP-HIL input devices o lan(7) special files o pty(7) special files o sockets AUTHOR
was developed by HP and the University of California, Berkeley. SEE ALSO
fcntl(2), poll(2), read(2), sigprocmask(2), write(2), thread_safety(5), select(2)
All times are GMT -4. The time now is 09:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy