I'm designing some reporting system on Raspberry Pi system which connects to world thru 3G usb modem controlled by pppd.

99,999% of time connection works ok, but sometimes it drops and further reconnect attempts fail unless modem is re-plugged physically.

As in production box will work remotely with no physical access to it so I have to manage it somehow.

My idea is to run at system start, some kind of script in separate thread see below pseudocode:

  start_pppd # may_be limiting retries not to default 10, but to, say, 3
    reset_usb_port_programmatically #I have tools for that
  • How can I get pppd exit code?
  • Should I use another approach (which)?

After calling 'pppd' you need get value of variable '$?'.

$? - get exit code of last program.

For background processes '$!' may be useful with some cover.

$! - get PID of last background process that was executed.

Example scenario:

run_background_process &
wait $pid_of_background_process
echo "Result code of background process: "$?
| improve this answer | |
  • Yury, ppd is running on background so you will get 0 always – DmitryD Mar 6 '18 at 14:18
  • @DmitryD, I've supplemented answer. – Yurij Goncharuk Mar 6 '18 at 14:39
  • Solution you proposed doesn't work even with supplement, but thanks for your try! – DmitryD Mar 14 '18 at 17:05


Put 'nodetach' as command-line argument to pppd and daemon will not fork itself. All is needed then is standard 'echo $?' in next line of script:

pppd call my_provider nodetach maxfail 3
echo $?
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.