Multithreading app that lauches and monitor another executable - multithreading

I found a code that launches a code using fork and execvp
but then by digging the web I realized it was not compatible with multithreading
so now I am quiet confused...
"the Pthreads standard specifies that an exec call from any thread must terminate all threads in the process and start a single new thread at main in the new image."
I definetely need multithreading, so in that context how do I launch an external executable, check if it is running and occasionaly kill it ?
thanks

I guess I'll use system() then, thanks for the wonderfull support
[comments dont work anymore]

Related

Does Firebase set and get run on the main thread?

Do they run on the same thread as the node process or do they run on a different thread? The CPU usage for my node process goes above 100% when I do a lot of sets and gets (and add several event listeners) on firebase. Any ideas why?
There is only 1 main thread in your Node application, all of your code and all library javascript code will run in this thread. When a library attempts to use IO, it may call upon libuv which runs in its own thread. Libraries may also have their own C++ bindings. Without knowing what you're doing and how the 3rd party library is implemented, it's impossible to tell.

Create different thread in node.js

can't we create different thread in node.js ?? I want to pool database for every 1 sec in different thread and run main program in one thread. I used setInterval function but, it seems, it is blocked or not acting as expected.
I am new at node,Nice reply would be nice.
This question has been already answered here. But to resume, you cannot create Thread (except if you use add-on) but you can run new NodeJs process.
setInterval won't work in this case. You probably need to write a batch script separated from the main program and invoke it using crontab. Checkout crontab man page

How to fork/clone an identical Node child process in the same sense as fork() of Linux system call?

So I was developing a server farm on Node which requires multiple processes per machine to handle the load. Since Windows doesn't quite get along with Node cluster module, I had to manually work it out.
The real problem is when I was forking Node processes, a JS module path was required as the first argument to the child_process.fork() function and once forked, the child process wouldn't inherit anything from its parent. In my case, I want a function that does similar thing as fork() system call in Linux, which clones the parent process, inherits everything and continues execution from exactly where the fork() is done. Can this be achieved on the Node platform?
I don't think node.js is ever going to support fork(2)
The comment from the node github page on the subject
https://github.com/joyent/node/issues/2334#issuecomment-3153822
We're not (ever) going to support fork.
not portable to windows
difficult conceptually for users
entire heap will be quickly copied with a compacting VM; no benefits from copy-on-write
not necessary
difficult for us to do
child_process.fork()
This is a special case of the spawn() functionality for spawning Node
processes. In addition to having all the methods in a normal
ChildProcess instance, the returned object has a communication channel
built-in. See child.send(message, [sendHandle]) for details.

Linux service and Source for cron job

I am new to linux and writing a service in C++ which spawns multiple threads and I am starting the service by calling it from init.d, but how should I send the terminate signal to my application from the script , so that my service terminates all the threads and exits.
And also where can I find the source code for any linux services. e.g. /etc.init.d/rc5.d/S14cron . It will be helpful in understanding how to implement a service.
The classic reference for this kind of question is Steven's "Advanced Programming in the UNIX Environment". You can find the source code to this text book here.
Depends what your application does.
Personally I'd keep a thread just for handling signals and call sigprocmask in the other threads to stop signals being delivered to them.
The main thread / signal handling thread (it is usually a good idea to make this the main thread) can then send a message to its threads to tell them to finish what they're doing and quit.
Alternatively, if you like the principle of crash-only, you could just call exit_group and be done with it :)

can a multithread program still be running after killing it in system monitor

Is it possible that a program which does not kill its threads properly before exiting still be running some piece of code somewhere even though it has been killed in system monitor? I am running ubuntu in a non virtual environment. My application is made with QT, it contains QThreads, a main thread and concurent functions.
If you kill the process then you kill all its threads. The only cause for concern would be if your application had spawned multiple processes - if that is the case then you may still have code executing on the machine.
This is all very speculative though as I don't know what operating system you code is running on, whether or not your application runs in a virtual environment, etc. Environment-specific factors are very relevant to the discussion, can you share a bit more about your application?
It is not possible, all modern heaviliy used operating systems manage these resources quite tightly. Threads cannot run without a process... They are all brantches from the original thread.
I don't know of any OS that doesn't fully terminate all it's threads when you kill the processes, it's possible to spawn child processes that live on after the main process has exited but in the case of threads i'd say it's not possible.

Resources