All Questions
12 questions
1
vote
1
answer
3k
views
How output one command with tee to standard ouput and also to pipe it to another command?
Maybe this is duplicate, I have not found any answers though, but how to use pipe to output one command to multiple outpus (e.g. send it to pipe, stdout, or command substitution)?
I have this line:
$ ...
2
votes
1
answer
604
views
How to get PIDs of shells in pipeline? [duplicate]
For example, I run
sleep 1 | sleep 2 | sleep 3 &
How do I get process ids of each part? I could examine output of jobs -l but its format may wary among shells and I am looking for a simpler way.
0
votes
1
answer
406
views
Interacting programs stdin and stdout (create a robot program to play a game)
The setup:
I have an executable file, that I "cannot edit", since I don't have the source code.
When I execute the program it reveals a game, where it hands me some numbers via stdout, for me to ...
3
votes
1
answer
367
views
How to can I cause an exit, from a script that receives data through a pipe, from another program?
I have Bash script that is used to process data, which is sent through a pipe from another process.
I'm trying to add a functionality that causes and exits after a certain condition is met, whose ...
1
vote
0
answers
305
views
Getting PID of sibling process in pipeline
I want to discover the PID of the producer process in a pipeline:
producer | consumer
I don't always control the producer process, I can request that they echo the PID from the producer like so:
log....
0
votes
1
answer
390
views
Pipeline running in parallel through creating multiple subshells
I read from this answer about the distinguish between | and ; https://unix.stackexchange.com/a/159492/318084;
Consider two commands A and B. When you write
A | B
A and B are executed in ...
18
votes
2
answers
9k
views
How to make reading and writing the same file in the same pipeline always "fail"?
Say I have the following script:
#!/bin/bash
for i in $(seq 1000)
do
cp /etc/passwd tmp
cat tmp | head -1 | head -1 | head -1 > tmp #this is the key line
cat tmp
done
On the key line, ...
8
votes
3
answers
8k
views
Kill the parent of a child pipe process
I have a small script to demonstrate what I want to do
#!/bin/bash
> z
tail -f z | grep 'd' &
echo $!
The $! gives the PID of the grep process. I want to be able to kill the tail process at ...
2
votes
1
answer
524
views
How are piped processes presented in ps output?
I have a following very simple script which watches /tmp directory for new files and output of inotifywait is piped to sed:
#!/bin/bash
/usr/local/bin/inotifywait -q -m /tmp --format %f | sed 's/a/b/...
0
votes
1
answer
167
views
Using $BASHPID in grep statement
I'm trying to exclude the PID of the subshell from the results returned by pgrep. Note that the name of the file is the same as the name passed to pgrep. Why does setting a variable equal to BASHPID ...
3
votes
1
answer
1k
views
How does the piping in this command ultimately achieve to kill the process?
I have seen the following line in a bash script for killing a process(in this case started with the command loadgen):
ps xww | grep -i "loadgen" | grep "PATTERNMATCH_FACT.xml" | cut -c1-5 | xargs -i ...
12
votes
3
answers
5k
views
Obtaining PID of command earlier in Pipeline
I'm writing a bash script to use inotifywait to monitor a directory and kick off actions when changes are detected. Something like:
inotifywait -m ... | while read f; do something; done
Since ...