10

If you have an M1-based Macbook you can tell if a process running on the machine is Apple/M1 or Intel/Rosetta in Activity Monitor, but is there a way to get this information on the command line?

I'd like to be able to quickly show a count of how many Intel processes are currently running on my machine under Rosetta.

Image of activity monitor showing Architecture

3
  • Have you got a screenshot you can share of activity monitor output?
    – Mr R
    Mar 19, 2021 at 3:38
  • It's definitely possible to tell from within the process (see developer.apple.com/documentation/apple-silicon/…) - i.e. you can make something that is aware of whether it's running in rosetta or not.
    – Mr R
    Mar 19, 2021 at 3:42
  • @MrR: yes: ibb.co/VTspjVj See the "Architecture" column on the right side. Apr 16, 2021 at 17:00

4 Answers 4

9

TL,DR: fuser /usr/libexec/rosetta/runtime

I know how to see which processes are non-native. I don't know how to tell between different non-native architectures, but in practice there's only one

A non-native process has the Rosetta runtime open. You can use fuser to list which processes have a given file open. You can use lsof to see what files a given process has open.

$ arch -x86_64 sleep 868686 &
[1] 65444
$ sleep 123123123 &
[2] 65446
$ fuser /usr/libexec/rosetta/runtime
/usr/libexec/rosetta/runtime: 65444
$ lsof -p65444 -p65446 | grep /usr/libexec/rosetta/runtime
sleep   65444 gilles  txt    REG   1,18    220064 1152921500312773394 /usr/libexec/rosetta/runtime

You'll need sudo to see other users' processes (but normally system processes should be native).

2

Here is some snippet to check all Rosetta 2 pids and inspect them:

ps -p `fuser /usr/libexec/rosetta/runtime | sed -e 's/.*: //' | sed -e 's/ /,/g'`
2
  • 1
    or ps -p `fuser /usr/libexec/rosetta/runtime 2> /dev/null` Mar 28 at 12:36
  • 1
    ps: option requires an argument -- p is returned if no rosetta pid processes are running.
    – l --marc l
    Apr 24 at 16:05
2

This actually can be done with AppleScript if you know the PID of the process:

osascript -e 'tell application "System Events" to return architecture of processes whose unix id is 758'
-1

You can definitely rule out some things (go to the terminal). e.g.

# ps -ef | grep -i firefox$
  502 56288     1   0 11Mar21 ??       207:43.89 /Applications/Firefox.app/Contents/MacOS/firefox

USE the executable name and pass to file command.

# file /Applications/Firefox.app/Contents/MacOS/firefox
/Applications/Firefox.app/Contents/MacOS/firefox: Mach-O 64-bit executable x86_64

So if that gives you x86_64 it has to be running under Rosetta - it's got only x86_64 architecture (the pre-M1 one).

On a M1 machine some things ship with universal binaries - for instance do the same thing for Safari and I get something like this (sorry machine is air-gapped .. this is TCP-over-ME so may not be 100% correct :-)

# file /Applications/Safari.app/Contents/MacOS/Safari
/Applications/Safari.app/Contents/MacOS/Safari:Mach-O universal binary with 2 architectures: [x86_64:Mach_o 64 bit executable x86_64][arm64e:Mach-o 64-bit executable arm64e]

.. and then proceeds to give output that is for each architecture ... According to Apple it will "prefer" arm64e.

2
  • 2
    Off topic, but: "sorry machine is air-gapped .. this is TCP-over-ME" That's not an air gap! Mar 19, 2021 at 5:25
  • 3
    This just shows for which architectures a binary is compiled, it doesn't show the architecture it's running under.
    – nohillside
    Nov 17, 2021 at 10:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .