Aravind Vijayan Aravind Vijayan - 11 days ago 6
Linux Question

when a process acquire resources

A script file that reside in a server that have ssh access to many other servers , take list of servers from another input file one by one and execute some commands in respective servers, when we can update the input file without affecting input of first process, and run the script with second list of servers.

Answer

When you run a command like file > my_script the contents located at file are piped into my_script (as a file descriptor). This decouples the contents from the name, meaning you can immediately modify/replace file in another process.

If you instead run a command like my_script file you're passing the name "file" to my_script, which may read from that file at any point (or write to it, delete it, etc.), thus you can't safely change file while the script is running. Notably this doesn't happen immediately; a long running process might not read from file until much later, after you've already edited the file.

Therefore if you design your program to read from stdin you can safely modify the input file and re-run the command while the first process is still running.

Comments