Skip to main content
fixed some wording
Source Link

Okay, so this might be a very silly question and I don't write shell scripts too often. I'm trying to start 3 processes in the background, one after the another within a shell script, for example:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PROCESS3 &

Here is the problem. I need to start these processes in the same order as shown. Also, the PID of the PROCESS2 needs to be passed as the command line argument to the PROCESS3. All of these processes run in the infinite loop and they do work smoothly when ran in 3 separate terminals.

I tried:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PID_PROCESS2=$!
PROCESS3 ${PID_PROCESS2} &

This starts the PROCESS1 and PROCESS3 but the PROCESS2 exits immediately without printing any error. It just vanishes. The ps command shows no traces of PROCESS2. Printing the PID_PROCESS2 givesreturns some value 'p' and the PROCESS3 runs just fine with the value 'p' as its argument. What's the problem and where am I lacking?

PROBABLY IMPORTANT DETAILS

  1. In the above example, I'm using the qualified paths to invoke the respective processes and all of them are native binaries and are in the same directory. For example,

     #!/bin/sh
     /usr/bin/PROCESS1 &
    

    The output of ps is as described above,

     $ps | grep "/path/to/PROCESS"
     10064 root 16536 S /path/to/PROCESS1
     10066 root 11084 S /path/to/PROCESS3 10065
    

    which clearly tells the PROCESS2 started but exited for some unknown reason.

  2. PROCESS2 communicates with PROCESS1 via a FIFO (named pipe) and it's a one-way communication.

WORKAROUND

#/bin/sh
/path/to/PROCESS1 &
/path/to/PROCESS2 & PROCESS2_PID=$!
export P2PID=${PROCESS2_PID}
sh -c "/path/to/PROCESS3 ${P2PID}"

This seems to do the job with one extra process for sh.

$ps | grep "/path/to/PROCESS"
10174 root 16536 R /path/to/PROCESS1
10175 root 71720 S /path/to/PROCESS2
10177 root 27772 S sh -c /path/to/PROCESS3 10175
10076 root 11084 S /path/to/PROCESS3 100175

But I still don't have any idea why this works. Can someone suggest what sort of "magic" happened in this case?

Okay, so this might be a very silly question and I don't write shell scripts too often. I'm trying to start 3 processes in the background, one after the another within a shell script, for example:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PROCESS3 &

Here is the problem. I need to start these processes in the same order as shown. Also, the PID of the PROCESS2 needs to be passed as the command line argument to the PROCESS3. All of these processes run in the infinite loop and they do work smoothly when ran in 3 separate terminals.

I tried:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PID_PROCESS2=$!
PROCESS3 ${PID_PROCESS2} &

This starts the PROCESS1 and PROCESS3 but the PROCESS2 exits immediately without printing any error. It just vanishes. The ps command shows no traces of PROCESS2. Printing the PID_PROCESS2 gives some value 'p' and the PROCESS3 runs just fine with the value 'p' as its argument. What's the problem and where am I lacking?

PROBABLY IMPORTANT DETAILS

  1. In the above example, I'm using the qualified paths to invoke the respective processes and all of them are native binaries and are in the same directory. For example,

     #!/bin/sh
     /usr/bin/PROCESS1 &
    

    The output of ps is as described above,

     $ps | grep "/path/to/PROCESS"
     10064 root 16536 S /path/to/PROCESS1
     10066 root 11084 S /path/to/PROCESS3 10065
    

    which clearly tells the PROCESS2 started but exited for some unknown reason.

  2. PROCESS2 communicates with PROCESS1 via a FIFO (named pipe) and it's a one-way communication.

WORKAROUND

#/bin/sh
/path/to/PROCESS1 &
/path/to/PROCESS2 & PROCESS2_PID=$!
export P2PID=${PROCESS2_PID}
sh -c "/path/to/PROCESS3 ${P2PID}"

This seems to do the job with one extra process for sh.

$ps | grep "/path/to/PROCESS"
10174 root 16536 R /path/to/PROCESS1
10175 root 71720 S /path/to/PROCESS2
10177 root 27772 S sh -c /path/to/PROCESS3 10175
10076 root 11084 S /path/to/PROCESS3 100175

But I still don't have any idea why this works. Can someone suggest what sort of "magic" happened in this case?

Okay, so this might be a very silly question and I don't write shell scripts too often. I'm trying to start 3 processes in the background, one after the another within a shell script, for example:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PROCESS3 &

Here is the problem. I need to start these processes in the same order as shown. Also, the PID of the PROCESS2 needs to be passed as the command line argument to the PROCESS3. All of these processes run in the infinite loop and they do work smoothly when ran in 3 separate terminals.

I tried:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PID_PROCESS2=$!
PROCESS3 ${PID_PROCESS2} &

This starts the PROCESS1 and PROCESS3 but the PROCESS2 exits immediately without printing any error. It just vanishes. The ps command shows no traces of PROCESS2. Printing the PID_PROCESS2 returns some value 'p' and the PROCESS3 runs just fine with the value 'p' as its argument. What's the problem and where am I lacking?

PROBABLY IMPORTANT DETAILS

  1. In the above example, I'm using the qualified paths to invoke the respective processes and all of them are native binaries and are in the same directory. For example,

     #!/bin/sh
     /usr/bin/PROCESS1 &
    

    The output of ps is as described above,

     $ps | grep "/path/to/PROCESS"
     10064 root 16536 S /path/to/PROCESS1
     10066 root 11084 S /path/to/PROCESS3 10065
    

    which clearly tells the PROCESS2 started but exited for some unknown reason.

  2. PROCESS2 communicates with PROCESS1 via a FIFO (named pipe) and it's a one-way communication.

WORKAROUND

#/bin/sh
/path/to/PROCESS1 &
/path/to/PROCESS2 & PROCESS2_PID=$!
export P2PID=${PROCESS2_PID}
sh -c "/path/to/PROCESS3 ${P2PID}"

This seems to do the job with one extra process for sh.

$ps | grep "/path/to/PROCESS"
10174 root 16536 R /path/to/PROCESS1
10175 root 71720 S /path/to/PROCESS2
10177 root 27772 S sh -c /path/to/PROCESS3 10175
10076 root 11084 S /path/to/PROCESS3 100175

But I still don't have any idea why this works. Can someone suggest what sort of "magic" happened in this case?

fixed more grammar
Source Link

Okay, so this might be a very silly question and I don't write shell scripts too often. I'm trying to start 3 processes in the background, one after the another within a shell script, for example:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PROCESS3 &

Here is the problem. I need to start these processes in the same order as shown. Also, the PID of the PROCESS2 needs to be passed as the command line argument to the PROCESS3. All of these processes run in the infinite loop and they do work smoothly when ran in 3 separate terminals.

I tried:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PID_PROCESS2=$!
PROCESS3 ${PID_PROCESS2} &

This starts the PROCESS1 and PROCESS3 but the PROCESS2 exits immediately without printing any error. It just vanishes. The ps command it shows no traces of PROCESS2. Printing the PID_PROCESS2 gives some value 'p' and the PROCESS3 runs just fine with the value 'p' as its argument. What's the problem and where am I lacking?

PROBABLY IMPORTANT DETAILS

  1. In the above example, I'm using the qualified paths to invoke the respective processes and all of them are native binaries and are in the same directory. For example,

     #!/bin/sh
     /usr/bin/PROCESS1 &
    

    #!/bin/sh /usr/bin/PROCESS1 & TheThe output of ps is as described above,

     $ps | grep "/path/to/PROCESS"
     10064 root 16536 S /path/to/PROCESS1
     10066 root 11084 S /path/to/PROCESS3 10065
    

    $ps | grep "/path/to/PROCESS" 10064 root 16536 S /path/to/PROCESS1 10066 root 11084 S /path/to/PROCESS3 10065 whichwhich clearly tells the PROCESS2 started but exited for some unknown reason.

  2. PROCESS2 communicates with PROCESS1 via a FIFO  (named pipe) and it's a one-way communication.

WORKAROUND

#/bin/sh
/path/to/PROCESS1 &
/path/to/PROCESS2 & PROCESS2_PID=$!
export P2PID=${PROCESS2_PID}
sh -c "/path/to/PROCESS3 ${P2PID}"

This seems to do the job with one extra process for sh.

$ps | grep "/path/to/PROCESS"
10174 root 16536 R /path/to/PROCESS1
10175 root 71720 S /path/to/PROCESS2
10177 root 27772 S sh -c /path/to/PROCESS3 10175
10076 root 11084 S /path/to/PROCESS3 100175

But I still don't have any idea why this works. Can someone suggest what sort of "magic" happened in this case?

Okay, so this might be a very silly question and I don't write shell scripts too often. I'm trying to start 3 processes in the background, one after the another within a shell script, for example:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PROCESS3 &

Here is the problem. I need to start these processes in the same order as shown. Also, the PID of the PROCESS2 needs to be passed as the command line argument to the PROCESS3. All of these processes run in the infinite loop and they do work smoothly when ran in 3 separate terminals.

I tried:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PID_PROCESS2=$!
PROCESS3 ${PID_PROCESS2} &

This starts the PROCESS1 and PROCESS3 but the PROCESS2 exits immediately without printing any error. It just vanishes. The ps command it shows no traces of PROCESS2. Printing the PID_PROCESS2 gives some value 'p' and the PROCESS3 runs just fine with the value 'p' as its argument. What's the problem and where am I lacking?

PROBABLY IMPORTANT DETAILS

  1. In the above example, I'm using the qualified paths to invoke the respective processes and all of them are native binaries and are in the same directory. For example,

    #!/bin/sh /usr/bin/PROCESS1 & The output of ps is as described above,

    $ps | grep "/path/to/PROCESS" 10064 root 16536 S /path/to/PROCESS1 10066 root 11084 S /path/to/PROCESS3 10065 which clearly tells the PROCESS2 started but exited for some unknown reason.

  2. PROCESS2 communicates with PROCESS1 via a FIFO(named pipe) and it's a one-way communication.

WORKAROUND

#/bin/sh
/path/to/PROCESS1 &
/path/to/PROCESS2 & PROCESS2_PID=$!
export P2PID=${PROCESS2_PID}
sh -c "/path/to/PROCESS3 ${P2PID}"

This seems to do the job with one extra process for sh.

$ps | grep "/path/to/PROCESS"
10174 root 16536 R /path/to/PROCESS1
10175 root 71720 S /path/to/PROCESS2
10177 root 27772 S sh -c /path/to/PROCESS3 10175
10076 root 11084 S /path/to/PROCESS3 100175

But I still don't have any idea why this works. Can someone suggest what sort of "magic" happened in this case?

Okay, so this might be a very silly question and I don't write shell scripts too often. I'm trying to start 3 processes in the background, one after the another within a shell script, for example:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PROCESS3 &

Here is the problem. I need to start these processes in the same order as shown. Also, the PID of the PROCESS2 needs to be passed as the command line argument to the PROCESS3. All of these processes run in the infinite loop and they do work smoothly when ran in 3 separate terminals.

I tried:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PID_PROCESS2=$!
PROCESS3 ${PID_PROCESS2} &

This starts the PROCESS1 and PROCESS3 but the PROCESS2 exits immediately without printing any error. It just vanishes. The ps command shows no traces of PROCESS2. Printing the PID_PROCESS2 gives some value 'p' and the PROCESS3 runs just fine with the value 'p' as its argument. What's the problem and where am I lacking?

PROBABLY IMPORTANT DETAILS

  1. In the above example, I'm using the qualified paths to invoke the respective processes and all of them are native binaries and are in the same directory. For example,

     #!/bin/sh
     /usr/bin/PROCESS1 &
    

    The output of ps is as described above,

     $ps | grep "/path/to/PROCESS"
     10064 root 16536 S /path/to/PROCESS1
     10066 root 11084 S /path/to/PROCESS3 10065
    

    which clearly tells the PROCESS2 started but exited for some unknown reason.

  2. PROCESS2 communicates with PROCESS1 via a FIFO  (named pipe) and it's a one-way communication.

WORKAROUND

#/bin/sh
/path/to/PROCESS1 &
/path/to/PROCESS2 & PROCESS2_PID=$!
export P2PID=${PROCESS2_PID}
sh -c "/path/to/PROCESS3 ${P2PID}"

This seems to do the job with one extra process for sh.

$ps | grep "/path/to/PROCESS"
10174 root 16536 R /path/to/PROCESS1
10175 root 71720 S /path/to/PROCESS2
10177 root 27772 S sh -c /path/to/PROCESS3 10175
10076 root 11084 S /path/to/PROCESS3 100175

But I still don't have any idea why this works. Can someone suggest what sort of "magic" happened in this case?

fixed grammar.
Source Link

Okay, so this might be a very silly question and I don't write shell scripts too often. I'm trying to start 3 processes in the background, one after the another within a shell script, for example:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PROCESS3 &

Here is the problem. I need to start these processes in the same order as shown. Also, the PID of the PROCESS2 needs to be passed as the command line argument to the PROCESS3. All of these processes run in the infinite loop and they do work smoothly when ran in 3 separate terminals. 

I tried:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PID_PROCESS2=$!
PROCESS3 ${PID_PROCESS2} &

This starts the PROCESS1 and PROCESS3 but the PROCESS2 exits immediately without printing any error. It just vanishes. The ps command it shows no traces of PROCESS2. Printing the PID_PROCESS2 gives some value 'p' and the PROCESS3 runs just fine with the value 'p' as its argument. WhatsWhat's the problem and where am I lacking?

PROBABLY IMPORTANT DETAILS

  1. In the above example, I'm using the qualified paths to invoke the respective processes and all of them are native binaries and are in the same directory. For example,

    #!/bin/sh /usr/bin/PROCESS1 & The output of ps is as described above,

    $ps | grep "/path/to/PROCESS" 10064 root 16536 S /path/to/PROCESS1 10066 root 11084 S /path/to/PROCESS3 10065 which clearly tells the PROCESS2 started but exited for some unknown reason.

  2. PROCESS2 communicates with PROCESS1 via a FIFO(named pipe) and itsit's a one-way communication.

WORKAROUND

#/bin/sh
/path/to/PROCESS1 &
/path/to/PROCESS2 & PROCESS2_PID=$!
export P2PID=${PROCESS2_PID}
sh -c "/path/to/PROCESS3 ${P2PID}"

This seems to do the job with one extra process for sh.

$ps | grep "/path/to/PROCESS"
10174 root 16536 R /path/to/PROCESS1
10175 root 71720 S /path/to/PROCESS2
10177 root 27772 S sh -c /path/to/PROCESS3 10175
10076 root 11084 S /path/to/PROCESS3 100175

But I still don't have any idea why this works. Can someone suggest what sort of "magic" happened in this case?

Okay, so this might be a very silly question and I don't write shell scripts too often. I'm trying to start 3 processes in the background, one after the another within a shell script, for example:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PROCESS3 &

Here is the problem. I need to start these processes in the same order as shown. Also, the PID of the PROCESS2 needs to be passed as the command line argument to the PROCESS3. All of these processes run in the infinite loop and they do work smoothly when ran in 3 separate terminals. I tried:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PID_PROCESS2=$!
PROCESS3 ${PID_PROCESS2} &

This starts the PROCESS1 and PROCESS3 but the PROCESS2 exits immediately without printing any error. It just vanishes. The ps command it shows no traces of PROCESS2. Printing the PID_PROCESS2 gives some value 'p' and the PROCESS3 runs just fine with the value 'p' as its argument. Whats the problem and where am I lacking?

PROBABLY IMPORTANT DETAILS

  1. In the above example, I'm using the qualified paths to invoke the respective processes and all of them are native binaries and are in the same directory. For example,

    #!/bin/sh /usr/bin/PROCESS1 & The output of ps is as described above,

    $ps | grep "/path/to/PROCESS" 10064 root 16536 S /path/to/PROCESS1 10066 root 11084 S /path/to/PROCESS3 10065 which clearly tells the PROCESS2 started but exited for some unknown reason.

  2. PROCESS2 communicates with PROCESS1 via a FIFO(named pipe) and its a one-way communication.

WORKAROUND

#/bin/sh
/path/to/PROCESS1 &
/path/to/PROCESS2 & PROCESS2_PID=$!
export P2PID=${PROCESS2_PID}
sh -c "/path/to/PROCESS3 ${P2PID}"

This seems to do the job with one extra process for sh.

$ps | grep "/path/to/PROCESS"
10174 root 16536 R /path/to/PROCESS1
10175 root 71720 S /path/to/PROCESS2
10177 root 27772 S sh -c /path/to/PROCESS3 10175
10076 root 11084 S /path/to/PROCESS3 100175

But I still don't have any idea why this works. Can someone suggest what sort of "magic" happened in this case?

Okay, so this might be a very silly question and I don't write shell scripts too often. I'm trying to start 3 processes in the background, one after the another within a shell script, for example:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PROCESS3 &

Here is the problem. I need to start these processes in the same order as shown. Also, the PID of the PROCESS2 needs to be passed as the command line argument to the PROCESS3. All of these processes run in the infinite loop and they do work smoothly when ran in 3 separate terminals. 

I tried:

#!/bin/sh
PROCESS1 &
PROCESS2 &
PID_PROCESS2=$!
PROCESS3 ${PID_PROCESS2} &

This starts the PROCESS1 and PROCESS3 but the PROCESS2 exits immediately without printing any error. It just vanishes. The ps command it shows no traces of PROCESS2. Printing the PID_PROCESS2 gives some value 'p' and the PROCESS3 runs just fine with the value 'p' as its argument. What's the problem and where am I lacking?

PROBABLY IMPORTANT DETAILS

  1. In the above example, I'm using the qualified paths to invoke the respective processes and all of them are native binaries and are in the same directory. For example,

    #!/bin/sh /usr/bin/PROCESS1 & The output of ps is as described above,

    $ps | grep "/path/to/PROCESS" 10064 root 16536 S /path/to/PROCESS1 10066 root 11084 S /path/to/PROCESS3 10065 which clearly tells the PROCESS2 started but exited for some unknown reason.

  2. PROCESS2 communicates with PROCESS1 via a FIFO(named pipe) and it's a one-way communication.

WORKAROUND

#/bin/sh
/path/to/PROCESS1 &
/path/to/PROCESS2 & PROCESS2_PID=$!
export P2PID=${PROCESS2_PID}
sh -c "/path/to/PROCESS3 ${P2PID}"

This seems to do the job with one extra process for sh.

$ps | grep "/path/to/PROCESS"
10174 root 16536 R /path/to/PROCESS1
10175 root 71720 S /path/to/PROCESS2
10177 root 27772 S sh -c /path/to/PROCESS3 10175
10076 root 11084 S /path/to/PROCESS3 100175

But I still don't have any idea why this works. Can someone suggest what sort of "magic" happened in this case?

fixed grammer
Source Link
Loading
added 1068 characters in body
Source Link
Loading
added an important detail
Source Link
Loading
Source Link
Loading