linux
Run several jobs parallelly and Efficiently
As Mark Setchell says: GNU Parallel. find scripts/ -type f | parallel If you insists on keeping 8 CPUs free: find scripts/ -type f | parallel -j-8 But usually it is more efficient simply to use nice as that will give you all 48 cores when no one else needs them: find scripts/ -type f … Read more
How is Stack memory allocated when using ‘push’ or ‘sub’ x86 instructions?
Answer recommended by Intel
What does O_DIRECT really mean?
(This answer pertains to Linux – other OSes may have different caveats/semantics) Let’s start with the sub-question: If I open a file with O_DIRECT flag, does it mean that whenever a write(blocking mode) to that file returns, the data is on disk? No (as @michael-foukarakis commented) – if you need a guarantee your data made … Read more
Managing log files created by cron jobs
The best way to manage cron logs is to have a wrapper around each job. The wrapper could do these things, at the minimum: initialize environment redirect stdout and stderr to log run the job perform checks to see if job succeeded or not send notifications if necessary clean up logs Here is a bare … Read more
Does Linux guarantee the contents of a file is flushed to disc after close()?
From “man 2 close“: A successful close does not guarantee that the data has been successfully saved to disk, as the kernel defers writes. The man page says that if you want to be sure that your data are on disk, you have to use fsync() yourself.
Run a shell command when a file is added
I don’t know how people are uploading content to this folder, but you might want to use something lower-tech than monitoring the directory with inotify. If the protocol is FTP and you have access to your FTP server’s log, I suggest tailing that log to watch for successful uploads. This sort of event-triggered approach will … Read more
How can I remove the last character of a file in unix?
A simpler approach (outputs to stdout, doesn’t update the input file): sed ‘$ s/.$//’ somefile $ is a Sed address that matches the last input line only, thus causing the following function call (s/.$//) to be executed on the last line only. s/.$// replaces the last character on the (in this case last) line with … Read more
Handling multiple SIGCHLD
On Linux, multiple children terminating before you read a SIGCHLD with signalfd() will be compressed into a single SIGCHLD. This means that when you read the SIGCHLD signal, you have to clean up after all children that have terminated: // Do this after you’ve read() a SIGCHLD from the signalfd file descriptor: while (1) { … Read more
Maximum length of command line argument that can be passed to SQL*Plus?
Try with: xargs –show-limits </dev/null Your environment variables take up 2446 bytes POSIX upper limit on argument length (this system): 2092658 POSIX smallest allowable upper limit on argument length (all systems): 4096 Maximum length of command we could actually use: 2090212 Size of command buffer we are actually using: 131072 There is no limit per … Read more