Bash script: Why process don't run in background?
Hello!
I'm trying to build a simple daemon and I'm struggling with bash. I'll try to explain what happens: 1. The execution works fine when I execute manually the command in the shell. Like: # coproc software* param 2. When I try to execute the same line inside a bash script, the software is executed and ended immediately. I tried use nohup, screen, coproc... *software was written in C and waits for ENTER press command twice times to be ended. Could anyone help? |
Show exactly the commands that you issue.
Show the line(s) in the bash script executing your program. Show terminal output. Run your script with bash -x /path/to/script and copy relevant output here. jlinkels |
Hi, jlinkels!
Follows the script that executes the main software. Code:
#!/bin/bash Code:
$ ./script Code:
$ bash -x script.sh Code:
$ coproc nfcDemoApp poll It seems that coproc is not invoked inside the script. I didn't expect this behavior. |
So you wrote coproc to prompt for user input? Or just to wait for user input? You didn't really respond to jlinkels requests. Maybe you could rewrite the script so it prompts for user input. I'm still not clear on what the problem is.
|
@AwesomeMachine,
I didn't understand. I think that I answered all questions. Did I make any mistake? To make my question more clear: The tool "nfcDemoApp poll" must be executed automatically after system boot. There isn't any type of user interaction. The main problem is to put the tool running in the background. When I do manually it works but fails inside a script. It's not common this issue in others applications... :( |
Did you try
Code:
program & |
Quote:
|
What you're showing on the command line is not what's in the bash script...
...and nothing you've posted has anything to do with running in background...running in a script is not running in background. So, I'm a tad confused about what your problem actually is... To run the command in a script, put the command in the script. i.e.: Code:
#!/bin/bash |
He means the program terminates when it's called from the script, whereas it runs as a daemon if it's called from the command line.
|
Cut the default file handles and send to background
Code:
/usr/local/sbin/nfcDemoApp poll >/dev/null </dev/null 2>&1 & (Actually all that should happen in the daemon...) |
Hi!
Quote:
Quote:
I'm investigating the nfcDemoApp source code (developed by NXP) and this software apparently cannot be detached by the shell. The software takes input data from i2c (treating it like a keyboard or other input device) and when I tried to run the coproc command inside a script, I assume the software does not detect the input and closes because of that. Quote:
Thanks for the attention, guys! |
I might be totally on the wrong track, but when nfcDemoApp is called from a script, it is the child process of that script, isn't it? So the script runs, calls coproc. Coproc executes nfcDemoApp, backgrounds it and then returns to the calling script. The calling script terminates and kills all its child processes. Which is nfcDemoApp.
I.e. backgrounding does not disconnect the background program from the calling script. It is just backgrounded, which means stdin and stdout are disconnected from the keyboard and terminal. If you start and background a program in the shell, and then close the shell. The backgrounded program will be closed as well. Running from the shell, you can disown the backgrounded program. Then it continues to run. You can also start the program with nohup. Although I am not sure it continues when the script terminates. It continues when you close your shell. I am totally not sure how all this works with coproc. Summarizing, this should be working from withing a script. Code:
/path/to/your/program >/dev/null &disown jlinkels |
Jlinkels, sorry for answer you today.
Quote:
Opening a new terminal after boot, doing automatic login and execute the software works. Yes, that is a poor solution, but was the unique alternative. :( |
what I don't understand: you need to check the logs of that app, why it was died (if available).
If I understand well it runs from a terminal, but won't run without terminal. That is expected if user input was required, but no tty attached to the process. |
Quote:
The app must be in continuous looping and never die. The software runs without terminal but only if I type "coproc nfcDemoApp" in shell even I close the terminal after... It's weird. |
All times are GMT -5. The time now is 02:50 AM. |