How to check if a process is running under Rosetta with terminal - macos-big-sur

I know that one can use Activity Monitor to check if a process is running via Rosetta on Apple Silicon. I wonder if there is a way to do the same with the terminal?
Edit:
The process is some other application, so if there is a way to check if this process is running in Rosetta a possible command could maybe have the syntax:
$ is_running_under_rosetta <pid>
which would output
yes or no.

By using following command you can check if the process is running under Rosetta(1) or not(0, natively).
sysctl -n sysctl.proc_translated

Confirm that you are using the Native Terminal by typing arch, which should return arm64: Terminal app screenshot running arch command and returning arm64

Related

How to install hcitool in mac os terminal

Hello there guys i have been trying to use hcitool on mac os terminal but whenever i type hcitool scan the following error is appeared -bash: hcitool: command not found i have tried pip install hci and pip install hcitool but the following error is shown
ERROR: Could not find a version that satisfies the requirement gatttool (from versions: none)
ERROR: No matching distribution found for gatttool
please help me with this
Commands such as hcitool, gatttool, hciconfig, etc. are part of the BlueZ package which works on Linux only. MacOS on the other hand is UNIX-core and therefore the commands will not run on a MacOS operating system. There have been hacks before to get some sort of functionality on MacOS OSs but the solution is always incomplete.
Your next best bet will be to use a Virtual Machine running a Linux guest (e.g. Ubuntu) and then use the BlueZ commands from within that VM OS.
I hope this helps.
Get yourself a Docker container up and running. You can write scripts that you keep in a shared volume between the host and the container (meaning you don't have to log into the container). You can then execute those scripts from your OSX terminal, to run in the container.
HTH

Run a C++ program in Clion as root

I'm trying to run a program written in C++ by using CLion v1.2 as super user. Anyone here knows how to run it as superuser? I'm using CMake.
I solved this by remote debugging on local machine. I run gdbserver with root privileges and connected to it from CLion.
To start gdbserver sudo gdbserver :port myapp, configure remote GDB debug with port
This was already implemented on CLion, starting 2020.3:
https://www.jetbrains.com/help/clion/debug-as-root.html
If you are asking to run the debugger as sudo/administrator, I had the same issue. On Linux you can open CLion as sudo and gdb will not have root permission issues running an executable:
sudo ./clion.sh
I would guess that you could right click in Windows and "Run as administrator" to get the same result.
There is a feature request into JetBrains to run the debugger as root that could use more up voting.
A workaround is:
From https://www.jetbrains.com/help/clion/attaching-to-local-process.html#prereq-ubuntu
If you are using CLion on Ubuntu (or probably, on some other Linux distribution), upon the first attempt to attach to the local process you can get the ptrace: Operation not permitted. error message. To disable it and enable attach to the local process feature, do the following:
To disable this restriction temporarily, enter the command:
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
To disable this restriction permanently, open the file /etc/sysctl.d/10-ptrace.conf for editing and change the line kernel.yama.ptrace_scope = 1 to kernel.yama.ptrace_scope = 0. To apply the changes, enter:
sudo service procps restart or restart your system, at your choice.
You can create a bash script to help you. For example, run.sh:
#!/usr/bin/env bash
echo $LOGIN_PASSWD | sudo -S yourExecutable --with=some-arguments
Don't forget to chmod a+x run.sh, and export the password of current account as an environment variable in Run/Debug Configurations.

Install "perf" on Mac

I need the "perf" utility to monitor the program on my Mac. I know linux comes with it, but is it available on Mac?
I am working on a OSX 10.9 Mavericks and tried "port search" for perf or linux-tools, but I couldn't get any results.
As #Sami Laine said in his comment, the Linux perf tool is dependent on Linux specific code. It relies on the perf_event_open system call which is not standardized.
Note: Maybe you could search how MacOSX users are using recent hardware performance counters.
Instruments app
On macOS you can use the Instruments application to profile your code.
I like to use the "Time Profiler" which will show you how much time your application is its various parts during execution. I haven't used perf myself, but from talks/videos that I've seen this seems to be the most common use.
To use the "Time Profiler":
Run Instruments, select Time Profiler
At the top left, select your target (executable).
Hit the Record button on the top left and let it run for a little
while.
Pause or Stop the execution and drill down on your calls in the main
window.
Hope this helps.
On OSX you can use sample together with filtercalltree.
Both have useful help text if you run them without commands, but an example invocation to sample process id 1234 for the default 10 seconds at 1ms resolution would be something like:
sample 1234 -f output.prof
filtercalltree output.prof
Once you've generated your call graph, FlameGraph is another great tool for visualizing it, and it supports sample call graphs via the stackcollpase-sample.awk script.
Check out Google Perf Tool
If you dont have brew installed:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
If you have brew installed:
brew install google-perftools
Reference: https://github.com/gperftools/gperftools

Can I just kill mongod to stop mongo?

I am very new at Mongo. I am running mongod as described here in Mac OS X. I am running two mongod processes from the command line. If I need to stop the mongod processes I just execute kill <pid of mongod>. Is it the recommended way to stop mongod?
It finally succeeded (Ubuntu 15.04) with
//1.find process by name:
$ pgrep mongo
1350
//2.kill mongod-process
$ kill 1350
This is quite late, but I had same problem now, and I found one easy way :
Esan-iMac:~$mongo admin --eval "db.shutdownServer()"
MongoDB shell version: 2.6.4
connecting to: admin
2015-02-19T10:54:22.574+0200 DBClientCursor::init call() failed
server should be down...
It's giving some odd messages, but it works.
And I made alias-command for running it easy.
alias stop-mongo='/opt/mongo/release/bin/mongo admin --eval "db.shutdownServer()"'
This works at least if you start your mongo manually (e.g. with --fork option).
The accepted answer by Esa is correct. Also, regarding whether using kill is recommended - yes, but with flag -2 or no flag, never use -9. As mentioned in docs.
kill -2 `pgrep mongo`
Alias
alias stopmongo='kill -2 `pgrep mongo`'
Windows
use admin
db.shutdownServer()
For systems with auth enabled, users may only issue db.shutdownServer() when authenticated to the admin database or via the localhost interface on systems without authentication enabled.
Linux
mongod --shutdown
you can also use
kill <mongod process ID>
see http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
For year of 2020:
Mongo should be installed through Brew, rather than the old school style on linux: i.e. tar.gz package download/uncompress/configure/run.
In the brew way, if Mongo is installed by brew tap mongodb/brew and brew install mongodb-community, you could do as follows to stop (and disable) it alike Systemd on Linux.
~ brew services list
Name Status User Plist
mongodb-community started zhengxin /Users/zhengxin/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
~ brew services stop mongodb-community
==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community)
terminal$ kill $(pgrep mongod)
this command can help killing the mongod process. sudo pkill -f mongod
Just encountered an issue with "just killing the mongod" in mac...
The mongod is kept running as a service by "launchctl" in mac systems. "just killing" it will kill that service.
Now to use mongo shell we do mongod again, however for other development purpose like connecting from node we need to make sure to run mongod time and again.
Other alternative is shut down the system and start again.
Better Way :
Start using launchctl to manage such services. Here is an example for that :
What is the correct way to start a mongod service on linux / OS X?
The easiest way is Ctrl + C, which worked for me on a blocking bash shell under El Capitan.
If you have configured autostart, killing the process won't help, new one will start immediately. In order to disable autostart, you have to locate the autostart file first. You can try to find the file using e.g.
find / -name "mongodb.plist" or locate "mongodb.plist"
After the file is found, remove the autostart config using (you can try without sudo first, it's not needed if you have done the installation using Homebrew):
sudo launchctl unload -w <file>
If you want to kill the process anyway and it's not using autostart, remember not to use kill -9 <PID>, it can damage the db. kill -1 <PID> or kill -15 <PID> should be safe options.
https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/
official guide
remember not to use kill -9
otherwise maybe you need to remove lock file in dbpath

Invoke Alt+F2 through script

The Alt+f2 in ubuntu shows up Run Application prompt. I can type any command there and open an application through it. How can i do the same programmatically, i mean that i have a command that should be passed to Alt+F2 programmatically. By program i mean a shell script
Have a look at xdotool.
You can use gmrun, which can be installed from the Ubuntu repos. Just sudo apt-get install gmrun. man gmrun for more info.
It's not exactly the same as the "run application dialog", but there's no clean way to bring that up from a script that I know of.

Resources