Entry :
There is a console application (JRE1.6 !!!), it creates a configuration for future child threads, it can start child threads and (need to be implemented) stop child threads.
1. The main thread main starts the child threads and terminates;
2. Child threads run in an infinite loop;
3. Child threads cannot create threads;


Tell me if I think correctly:
Stop child threads from main thread main with the command

String[] cmd = { "/bin/bash", "-c", "killall " + PID }; ProcessBuilder processBuilder = new ProcessBuilder( cmd ); Process process = processBuilder.start(); 

But for this method you need to know the pid of the child process.

Question :
How do I get the pid of the child process?

P.S.
I could only find information on how to get the PID of the parent process:

 String proccessName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName(); Long pid = Long.parseLong( proccessName.split( "@" )[0] ); 
  • explain what you mean by the notion of the Главный поток main запускает дочерние потоки . Thread.start() it run them with the help of some analogue of Thread.start() or is it launching a third-party application through the system? - Temka also
  • In the loop Thread.start () - Nikolay
  • First, we must learn to distinguish between processes and flows. Secondly, a call to killall from a java program is such an eerie crutch that I want to jump with a cry. Thirdly, the flow must manage its life cycle itself; it cannot be stopped from another flow. It is necessary to send all the generated threads a signal about the need to complete the work, and process it in the streams. - Sergey Gornostaev
  • 1) I learn to distinguish threads from processes. 2) I kind of wrote "Tell me if I think correctly:", the name of this as "eerie crutch" is enough, you don’t need to jump, because you can break something ....))) 3) In case of any errors in the stream, it will terminate and throw the SNMP trap in Zabbix, but there should still be a functionality to stop a specific stream from Main. 4) Why does all spawned threads send a completion message ??? each child thread performs in the loop some kind of action, all of them cannot be stopped for the sake of one. - Nikolay

0