-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
child_process.fork and child_process.exec do not work together. #10412
Comments
Do you have a standalone reproduction? Or at least, can you describe
In what way does it fail? child process share no state in node.js, this is very unlikely to be a node bug. Whatever is happeing is likely either a bug in your code, or possibly something android specific relating to how those processes run and interact. Does your system limit the number of concurring child processes you can run? |
When the exec get called while the active fork is running every process immediately goes defunct. In the output below the main process is 1365, the forked process is 1371, all other processes are attempts to run exec. I am running linux so android should have nothing to do with this issue. I don't believe that there is any child process limit, I have executed several fork bombs to test the raspberry pi's watchdog timer and it seems that it can take thousands of processes before crashing.
|
OK, then please provide a standalone repro on non-Android Linux. Interestingly, ps listing above shows 4 shell children waiting to be reaped by their parent node process (and one node child, presumably the fork), but you only have 3 calls to exec in your example code. Any ideas on why that is? I suggest you use |
So I have a working standalone below. Now I am even more confused as to what is causing the exec commands to fail. Anyway I guess this is an issue with my code and not an issue with the child_process library so I'll close the issue. If you have any other suggestions though please feel free to reply. master.js var fork = require('child_process').fork;
var exec = require('child_process').exec;
var oledHandler = fork('./oled-handler.js');
oledHandler.on('message', function(response) {
console.log(response);
});
var oledCnt = 0;
var oledInterval = setInterval(updateScreen, 2000);
var failed_wifi_reconnect_attempts = 0;
var checkWiFi = setInterval(WiFiCheck, 10000);
function updateScreen(){
//oled.clearDisplay(false);
if (oledCnt) {
oledHandler.send("1234");
oledCnt = 0;
}
else {
oledHandler.send("5678");
oledCnt = 1;
}
}
function WiFiCheck(){
child = exec('ping -c 1 192.168.0.1', function(error, stdout, stderr){
if(error) {
console.log("Offline - Attempting to bring up wlan0")
exec('ifup --force wlan0',function(error, stdout, stderr){
console.log("error: " + error);
console.log("stdout: " + stdout);
console.log("stderr: " + stderr);
if(error || stderr !== ""){
failed_wifi_reconnect_attempts++;
console.log("Failed to bring up wlan0\n" + stderr);
if (failed_wifi_reconnect_attempts == 5){
exec('shutdown -r now',function(error, stdout, stderr){
console.log(stdout);
});
}
}
else{
console.log("wlan0 back online");
}
});
}
else {
console.log("Online")
}
});
console.log(child.pid);
} oled-handler.js var i2c = require('i2c-bus');
var i2cBus = i2c.open(1, function (err) { if (err) throw err; });
var oled = require('oled-i2c-bus');
var font = require('oled-font-5x7');
var oledOpts = {
width: 128,
height: 64,
address: 0x3C
};
var oled = new oled(i2cBus, oledOpts);
process.on('message', function(msg) {
oledMessage(msg);
});
function oledMessage(msg){
oled.clearDisplay(false);
oled.setCursor(1, 1);
oled.writeString(font, 2, msg, 1, true);
} |
Version: 4.5.0
Platform: Raspberry Pi Zero Linux 4.4.21+ #911 armv6l GNU/Linux
Subsystem: Raspian Jesse Lite
I have created a test script to check and restore a wifi connection on the raspberry pi. It works fine when tested by itself. However when I add it to the application that I want it to be integrated with it fails to execute. The issue seems to be that I have a forked process also running from the child_process library. If I remove the fork from the main app and leave the exec code it again works as it did in the test script.
The text was updated successfully, but these errors were encountered: