# Read same file simultaneously with two different programs

**URL:** <https://community.unix.com/t/read-same-file-simultaneously-with-two-different-programs/324645>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [February 20, 2013, 8:18pm UTC](https://community.unix.com/t/read-same-file-simultaneously-with-two-different-programs/324645 "2013-02-20T20:18:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![torchij](https://community.unix.com/letter_avatar/torchij/32/5_5575768a8748004e209b776fc1b2916d.png) [@torchij](https://community.unix.com/u/torchij)\
**Post date:** [February 20, 2013, 8:18pm UTC](https://community.unix.com/t/read-same-file-simultaneously-with-two-different-programs/324645/1 "2013-02-20T20:18:24Z")

</div>

Hi all, I was just wondering if there are any consequences, or if its a problem to have a multiple scripts parsing (reading) the same file simultaneously.

For example, I have file.txt with lots of information.

```nohighlight
cat script1.sh
grep "awesome" file1.txt > awesome.txt

cat script2.sh
grep -v "awesome" file1.txt > notawesome.txt

```

Can both scripts run at the same time and read from file1.txt simultaneously?

Many thanks in advance,  
Torch

---

<div class="post-metadata">

**Author:** ![alister](https://community.unix.com/letter_avatar/alister/32/5_5575768a8748004e209b776fc1b2916d.png) [@alister](https://community.unix.com/u/alister)\
**Post date:** [February 20, 2013, 8:45pm UTC](https://community.unix.com/t/read-same-file-simultaneously-with-two-different-programs/324645/2 "2013-02-20T20:45:49Z")

</div>

Unsynchronized simultaneous reads are not a problem.

Regarding the example you gave, though, it could be accomplished in a single pass by a single process (sed or awk, to name a couple tools).

Regards,  
Alister

---

<div class="post-metadata">

**Author:** ![torchij](https://community.unix.com/letter_avatar/torchij/32/5_5575768a8748004e209b776fc1b2916d.png) [@torchij](https://community.unix.com/u/torchij)\
**Post date:** [February 20, 2013, 8:51pm UTC](https://community.unix.com/t/read-same-file-simultaneously-with-two-different-programs/324645/3 "2013-02-20T20:51:09Z")

</div>

Thanks for your response, Alister.

What do you mean by unsynchronized? The example I gave was just for simplicity, but typically the scripts are perl or python programs that read the file (gigabites in size). But don't write to it or append anything.

Just wondering if I am screwing things up by accessing the file with multiple programs.

Thanks again,  
Torch

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [February 20, 2013, 10:38pm UTC](https://community.unix.com/t/read-same-file-simultaneously-with-two-different-programs/324645/4 "2013-02-20T22:38:49Z")

</div>

Unsynchronized means the readers of the file read whatever they want to read whenever they need to read it.

You can have large number of processes reading a file at exactly the same time. If you have too many you can reach I/O saturation on huge files. On medium sized files the I/O systems kernel memory cache and disk controller cache can easily hold several GB's of data for a group of files on a system that is not starved for memory. On small desktops with 2GB of RAM this will not fly.

That said: two scripts scripta scriptb running in parallel launched from another bigscript

bigscript:

```nohighlight
scripta giantfile >output1 &
scriptb giantfile >output2 &
wait

```

put bigscript in background so you can keep working:

```nohighlight
bigscript 1>bigscript.log 2>&1 &

```

Or. run it with at:

```nohighlight
at -k now <<!
cd /home/me
/home/me/bigscript 
!

```

Any output (like errors) will be emailed to your UNIX account.

---

<div class="post-metadata">

**Author:** ![torchij](https://community.unix.com/letter_avatar/torchij/32/5_5575768a8748004e209b776fc1b2916d.png) [@torchij](https://community.unix.com/u/torchij)\
**Post date:** [February 26, 2013, 8:28pm UTC](https://community.unix.com/t/read-same-file-simultaneously-with-two-different-programs/324645/5 "2013-02-26T20:28:06Z")

</div>

Thank you so much for your very clear reply! That was very helpful.
