I have been running a server with:
go run server.go &
When I am done with the process, this requires me to kill the process. The way I have been doing this is with kill PID of the go run process.
However, I've noticed my server appears connected still. Investigating further it seems that there are other processes go is starting which appear to "keep alive" my server:
$ps aux | grep go
username 70481 0.0 0.0 573416816 5228 ?? S 3:15PM 0:00.63 /var/folders/wf/89r2567s5hv48lj1g9l65mbw0000gp/T/go-build062422854/command-line-arguments/_obj/exe/server
username 70472 0.0 0.0 573407408 7720 ?? S 3:15PM 0:00.80 go run server.go
When I kill this associated process, too, I see that my connection is released as expected.
Is there a better way to "really" kill a golang process than kill PID? Or is there a reason why there are these phantom processes?
I have resorted to killing both but this seems... strange.
$ go version
go version go1.5.4 darwin/amd64
The one you're calling the "phantom process" is your server, which is why killing it kills your server. The other is the "go run" utility itself, which is compiling your code and then running the resulting executable.
Related
In order to terminate the ghost process (process which hasn't terminated properly and hence it still pending to be killed)
I used the
kill -9 <process-id>
At times it works perfectly, and when I check the process after killing it, it is gone
ps -aux | grep python
However, surprisingly, now I am able to see the ghost process even after the kill command. What's the problem?
In the image above, I tried to kill the process with id 23756 but it still appears in ps aux
Referring to my answer to previous question of Visual Studio ghost process
VSCode kill running processes
Looks like, I had to close the debug process that was still incomplete. Basically, killing the application or closing the debug or something on those lines, helps you to terminate the ghost process.
I've turned a program I wrote into a service, and I have a bash script that runs to start up the actual program, since there are things that have to be started in a particular order. The contents of the startup script (called with start-stop-daemon from the init.d script look like :
./rfid_reader &
sleep 2
java ReaderClass &
This works fine, but how do I go about killing them when it comes time to stop the process?
I've seen pidfiles used, do I just get the PIDs of the two programs, write them to a file, and then kill them when it comes time to shut them down, or do I have to ps -ef | grep program to get their PIDs?
I don't think killall is a good idea to do this. You'd better to record the PID of the program started in background in some file(e.g. PID_FILE) and then kill $(<$PID_FILE) to stop it.
Please refer to this thread for how to get the PID the previous started background program.
Assuming you know the name of your program, you can kill them as below :
killall -KILL program_name
Is there a way to exit from gdb connnection without stopping / exiting running program ? I need that running program continues after gdb connection closed.
Is there a way to exit from gdb connnection without stopping / exiting running program ?
(gdb) help detach
Detach a process or file previously attached.
If a process, it is no longer traced, and it continues its execution. If
you were debugging a file, the file is closed and gdb no longer accesses it.
List of detach subcommands:
detach checkpoint -- Detach from a checkpoint (experimental)
detach inferiors -- Detach from inferior ID (or list of IDS)
Type "help detach" followed by detach subcommand name for full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.
Since the accepted (only other) answer does not specifically address how to shut down gdb without stopping the program under test, I'm throwing my hat into the ring.
Option 1
Kill the server from the terminal in which it's running by holding Ctrl+c.
Option 2
Kill the gdb server and/or client from another terminal session.
$ ps -u username | grep gdb
667511 pts/6 00:00:00 gdbserver
667587 pts/7 00:00:00 gdbclient
$ kill 667587
$ kill 667511
These options are for a Linux environment. A similar approach (killing the process) would probably also work in Windows.
I've installed and am exploring Yeoman but one thing that I can't seem to find an answer to is, how do I halt the grunt server from running?
Is this something that can be done from the terminal? It just sits and waits.
You can stop it with ctrl + c in terminal
If it's a task that is running in background you can find his process
id (pid) with ps aux | grep grunt and then kill it with kill {pid}
I have a master-workers architecture where the number of workers is growing on a weekly basis. I can no longer be expected to ssh or remote console into each machine to kill the worker, do a source control sync, and restart. I would like to be able to have the master place a message out on the network that tells each machine to sync and restart.
That's where I hit a roadblock. If I were using any sane platform, I could just do:
exec('ruby', __FILE__)
...and be done. However, I did the following test:
p Process.pid
sleep 1
exec('ruby', __FILE__)
...and on Windows, I get one ruby instance for each call to exec. None of them die until I hit ^C on the window in question. On every platform I tried this on, it is executing the new version of the file each time, which I have verified this by making simple edits to the test script while the test marched along.
The reason I'm printing the pid is to double-check the behavior I'm seeing. On windows, I am getting a different pid with each execution - which I would expect, considering that I am seeing a new process in the task manager for each run. The mac is behaving correctly: the pid is the same for every system call and I have verified with dtrace that each run is trigging a call to the execve syscall.
So, in short, is there a way to get a windows ruby script to restart its execution so it will be running any code - including itself - that has changed during its execution? Please note that this is not a rails application, though it does use activerecord.
After trying a number of solutions (including the one submitted by Byron Whitlock, which ultimately put me onto the path to a satisfactory end) I settled upon:
IO.popen("start cmd /C ruby.exe #{$0} #{ARGV.join(' ')}")
sleep 5
I found that if I didn't sleep at all after the popen, and just exited, the spawn would frequently (>50% of the time) fail. This is not cross-platform obviously, so in order to have the same behavior on the mac:
IO.popen("xterm -e \"ruby blah blah blah\"&")
The classic way to restart a program is to write another one that does it for you. so you spawn a process to restart.exe <args>, then die or exit; restart.exe waits until the calling script is no longer running, then starts the script again.