Running a command as Administrator using PowerShell?
If the current console is not elevated and the operation you're trying to do requires elevated privileges then you can start powershell
with the Run as Administrator option :
PS> Start-Process powershell -Verb runAs
Microsoft Docs: Start-Process
keep external process running after exit
I can't recreate the issue you are having. When I run the sleep
command and the goroutine terminates, it is still running when I search for it with ps
Update
- Doesn't work running it with the debugger in GoLand.
- Except if you enable run as
sudo
in the debug options window. - Without
sudo
: either withgo run
, or withdlv debug
or without the debugger in GoLand.
package main
import (
"os/exec"
)
func main() {
cmd := exec.Command("sleep", "99999999")
cmd.Start()
}
~/tempgo/process
▶ go run process.go
~/tempgo/process
▶ ps -ax | grep "sleep"
29907 ttys002 0:00.00 sleep 99999999
29925 ttys002 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox sleep
~/tempgo/process
How to kill process on GPUs with PID in nvidia-smi using keyword?
You can grep python in the nvidia-smi and then pass the PID to
the kill -9 command, e.g.
sudo kill -9 $( nvidia-smi | grep 'python' | sed -n
's/|\s*[0-9]\s([0-9])\s.*/\1/p' | sed '/^$/d')
how to keep subprocess running after program exit in golang?
The subprocess should continue to run after your process ends, as long as it ends cleanly, which won't happen if you hit ^C
.
What you can do is intercept the signals sent to your process so you can end cleanly.
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan,
syscall.SIGINT,
syscall.SIGKILL,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
s := <-sigchan
// do anything you need to end program cleanly
}()
package XXX is not in GOROOT when building a Go project
A pretty dumb conclusion (mostly on my part) but my issue came from having done go mod init
in each of the folders. after removing go.mod
and go.dep
from each of the folders I did go mod init
in, I could build without issue (through terminal)
Also, my packages in GoLand were not being detected because I had Go Modules enabled in the Settings. I disabled it and GoLand was able to index the external packages and my own packages.
Setting Windows PowerShell environment variables
Changing the actual environment variables can be done by
using the env: namespace / drive
information. For example, this
code will update the path environment variable:
$env:Path = "SomeRandomPath"; (replaces existing path)
$env:Path += ";SomeRandomPath" (appends to existing path)
Making change permanent
There are ways to make environment settings permanent, but
if you are only using them from PowerShell, it's probably
a lot better to use Powershell profiles script.
Everytime a new instance of Powershell starts, it look for specific script files (named profile files) and execute them if they do exist. You can edit one of these profile to customize your enviroment.
To know where those profile scripts are located in your computer type:
$profile
$profile.AllUsersAllHosts
$profile.AllUsersCurrentHost
$profile.CurrentUserAllHosts
$profile.CurrentUserCurrentHost
You can edit one of them, for example, by typing:
notepad $profile
Related Topics
How to Add an Icon to The Bash Prompt
Expect, Interact and Then Again Expect
Different CPU Cache Size Reported by /Sys/Device/ and Dmidecode
Receiving Multicast on a Server with Multiple Interfaces (Linux)
What Is The Size of Coap Packet
Short Command to Find Total Size of Files Matching a Wild Card
Find The Number of Files in a Directory
How to Check Out a Particular Version in Git from 'Git Log'
Opening Default Text Editor in Bash
How Are Interrupts Handled on Smp
How to Specify Which Version of Perl to Use on Centos
Trouble with Vagrant - "404 - Not Found"
How to Get Percentage of Processor Use with Bash
How Is a Memory Barrier in Linux Kernel Is Used
How to Check Character Encoding of a File in Linux
How to Access Raspberry Pi Qemu Vm via Network
Do I Need to "Enable" a Pcie Memory Region in a Linux 3.12 Driver