Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Last active November 7, 2025 01:29
Show Gist options
  • Select an option

  • Save billywhizz/2ed895a581c3ac406070ccbadd04e2c5 to your computer and use it in GitHub Desktop.

Select an option

Save billywhizz/2ed895a581c3ac406070ccbadd04e2c5 to your computer and use it in GitHub Desktop.
fifos

this will deadlock the process if we run it in same process as js

#include <fstream>
#include <iostream>
#include <string>
#include <sys/stat.h> // Required for mkfifo (on Unix/Linux)
#include <chrono>
#include <thread>
int main () {
const char* str = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
const char* myfifo = "my_pipe";
mkfifo(myfifo, 0666); // Create the FIFO (if it doesn't exist)
std::ofstream pipeOut("my_pipe");
if (pipeOut.is_open()) {
while (1) {
pipeOut << str << std::endl; // Data written in order
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
pipeOut.close();
}
return 0;
}
const fs = require('fs');
const net = require('net');
let bytes = 0
fs.open('./my_pipe', fs.constants.O_RDONLY | fs.constants.O_NONBLOCK, (err, fd) => {
console.log(err)
// Handle err
const pipe = new net.Socket({ fd });
// Now `pipe` is a stream that can be used for reading from the FIFO.
pipe.on('data', (data) => {
// process data ...
bytes += data.length
//console.log(data.length)
});
});
setInterval(() => {
console.log(bytes)
bytes = 0
}, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment