I try to execute a long run function from my main javascript file. I have 2 cpus so how can I just fork a function ?
Here is node.js documentation on forking and child processes in node.
http://nodejs.org/api/child_process.html
Looks like you might be able to do something like this.
var child = require('child_process').fork('child.js');
child.on("message", function(){});
And you would need the child.js file in this case.
For browser-side javascript you would use Web Workers for such a task, the functionality has been ported to NodeJS here Design of Web Workers for NodeJS which wraps child_process API call with the message passing abilities of Web Workers.