How to kill process inside container? Docker top command

When I reproduce your situation I see different PIDs between docker top <container> and docker exec -it <container> ps -aux. When you do docker exec the command is executed inside the container => should use container’s pid. Otherwise you could do the kill without docker straight from the host, in your case: sudo kill -9 … Read more

c# calculate CPU usage for a specific application

Performance Counters – Process – % Processor Time. Little sample code to give you the idea: using System; using System.Diagnostics; using System.Threading; namespace StackOverflow { class Program { static void Main(string[] args) { PerformanceCounter myAppCpu = new PerformanceCounter( “Process”, “% Processor Time”, “OUTLOOK”, true); Console.WriteLine(“Press the any key to stop…\n”); while (!Console.KeyAvailable) { double pct … Read more

How can I capture the stdout from a process that is ALREADY running

True solution for OSX Write the following function to your ~/.bashrc or ~/.zshrc. capture() { sudo dtrace -p “$1” -qn ‘ syscall::write*:entry /pid == $target && arg0 == 1/ { printf(“%s”, copyinstr(arg1, arg2)); } ‘ } Usage: example@localhost:~$ perl -e ‘STDOUT->autoflush; while (1) { print “Hello\n”; sleep 1; }’ >/dev/null & [1] 97755 example@localhost:~$ capture … Read more

How is socket connection being handled in a forked process

First, accept() the incoming connection. The accepting process now has a handle to the listening socket, and the newly accepted socket. Fork and: In the child: Close the listening socket. Do stuff with the accepted socket. In the parent: Close the accepted socket. Resume the accept loop. The various socket resources will be reclaimed when … Read more

How do ‘cluster’ and ‘worker_threads’ work in Node.js?

Effectively what you are differing is process based vs thread based. Threads share memory (e.g. SharedArrayBuffer) whereas processes don’t. Essentially they are the same thing categorically. cluster One process is launched on each CPU and can communicate via IPC. Each process has it’s own memory with it’s own Node (v8) instance. Creating tons of them … Read more

Start a background process in Python

While jkp’s solution works, the newer way of doing things (and the way the documentation recommends) is to use the subprocess module. For simple commands its equivalent, but it offers more options if you want to do something complicated. Example for your case: import subprocess subprocess.Popen([“rm”,”-r”,”some.file”]) This will run rm -r some.file in the background. … Read more

Starting a process in Java?

http://www.rgagnon.com/javadetails/java-0014.html import java.io.BufferedReader; import java.io.InputStreamReader; import java.nio.file.Paths; public class CmdExec { public static void main(String args[]) { try { // enter code here Process p = Runtime.getRuntime().exec( Paths.get(System.getenv(“windir”), “system32”, “tree.com /A”).toString() ); // enter code here try(BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()))) { String line; while ((line = input.readLine()) != null) { System.out.println(line); } } … Read more