Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Error EBUSY: resource busy or locked

Trying to run a Nodejs app to test Raspberry 3 B + Gpio Onoff Module but when i am trying to run the app getting this Error

fs.js:114
throw err;

Error: EBUSY: resource busy or locked, write
at Object.writeSync (fs.js:568:3)
at Object.writeFileSync (fs.js:1199:26)
at new Gpio (/home/pi/Desktop/pitesting/node_modules/onoff/onoff.js:96:10)
at Object.<anonymous> (/home/pi/Desktop/pitesting/blink.js:3:7)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)

Here is my App Code

var onoff = require('onoff');
var Gpio = onoff.Gpio,
  led = new Gpio(4, 'out'),
  interval;
interval = setInterval(function () {
  var value = (led.readSync() + 1) % 2;
  led.write(value, function () {
    console.log("Changed LED state to: " + value);
  });
}, 2000);
process.on('SIGINT', function () {
  clearInterval(interval);
  led.writeSync(0);
  led.unexport();
  console.log('Bye, bye!');
  process.exit();
});

Already Tried Fixes by updating and upgrading apt and reinstalling node modules.

Please Help me to resolve this issue.

like image 915
Syed Muhammad Danish Iqbal Avatar asked Mar 09 '19 19:03

Syed Muhammad Danish Iqbal


3 Answers

There are many answers on GitHub regarding this issue.

  • Some says npm cache clean this command executing on terminal solved the problem.

  • Others recommend to delete the entire directory your app is the folder in and re-install the packages and then try running the program.

  • Some also says that It is caused by the anti-malware software and recommend to disable it while running the program.

GitHub issue link: https://github.com/npm/npm/issues/13461

If it doesn't solve the issue, just change the GPIO pin to let's say 23 in coding and don't forget to physically replace LED from 4 to 23 too.

like image 100
5 revs Avatar answered Nov 06 '22 07:11

5 revs


This problem can occur when you try to write to a file that is open in an editor

like image 4
Eugene Avatar answered Nov 06 '22 08:11

Eugene


var onoff = require('onoff');
var Gpio = onoff.Gpio,
    led = new Gpio(4, 'out'),
    interval;
interval = setInterval(function () {
    var value = (led.readSync() + 1) % 2;
    led.write(value, function () {
        console.log("Changed LED state to: " + value);
    });
}, 2000);
process.on('SIGINT', function () {
    clearInterval(interval);
    led.writeSync(0);
    led.unexport();
    console.log('Bye, bye!');
    process.exit();
});
like image 3
Muhammad Areeb Siddiqui Avatar answered Nov 06 '22 06:11

Muhammad Areeb Siddiqui