python - Have bash script execute multiple programs as separate processes -
as title suggests how write bash script execute example 3 different python programs separate processes? , able gain access each of these processes see being logged onto terminal?
edit: again. forgot mention i'm aware of appending &
i'm not sure how access being outputted terminal each process. example run 3 of these programs separately on different tabs , able see being outputted.
you can run job in background this:
command &
this allows start multiple jobs in row without having wait previous 1 finish.
if start multiple background jobs this, share same stdout
(and stderr
), means output interleaved. example, take following script:
#!/bin/bash # countup.sh in `seq 3`; echo $i sleep 1 done
start twice in background:
./countup.sh & ./countup.sh &
and see in terminal this:
1 1 2 2 3 3
but this:
1 2 1 3 2 3
you don't want this, because hard figure out output belonged job. solution? redirect stdout
(and optionally stderr
) each job separate file. example
command > file &
will redirect stdout
and
command > file 2>&1 &
will redirect both stdout
, stderr
command
file
while running command
in background. this page has introduction redirection in bash. can view command's output "live" tail
ing file:
tail -f file
i recommend running background jobs nohup or screen user2676075 mentioned let jobs keep running after close terminal session, e.g.
nohup command1 > file1 2>&1 & nohup command2 > file2 2>&1 & nohup command3 > file3 2>&1 &
Comments
Post a Comment