Linux command 'w' - how is this as command written in Android shell?


Question

I am searching for similiar commands in Android shell - as they are used in Linux like these commands - what can I type in Android terminal for :




w



who



whoami




?



Thank you.


Answer

Linux commands w and who read login information from file /var/run/utmp. Traditional Linux sysV login records/logs like utmp, wtmp, btmp and lastlog are set and read by some programs that make use of GNU libc (the most commonly used C library on Linux distros) and other libc's. These files contain information about currently and previously logged-in users.



However there is no concept of Linux console login on Android as it isn't designed for multiple user logins. Virtual terminals are disabled on Android by default, init doesn't start getty, and hence there is no login, no login manager (like logind), no shell at startup and no user sessions, and therefore no login files. Android boots directly to GUI. Other CLI programs like sshd that read/write these login files are also not part of Android. So Android's Bionic libc neither provides the functions of utmp.h, nor filesystem hierarchy contains /var/log or /var/run. However if a program linked against standard Linux libc's is used on Android, it will try to access these login files. But if a program - like w, who, users, last and lastlog - is totally dependent on these files, it simply won't work. You can use busybox such as yashdsaraf's to get all these commands on Android.



Linux command whoami gets the (effective) UID of process by making syscall geteuid directly to kernel and then on Linux , if possible, resolves ID to name using name resolution mechanisms like directly from /etc/passwd, /etc/group or through NSS, NSCD etc. id command additionally does getgid and getgroups as well. So these commands work on Android as expected and - along with other similar tools logname and groups - are part of toybox; Android's choice for all-in-one Linux command line tool.

Bionic libc's wrapper functions (that apps actaully use through Android APIs to get UID) and kernel syscalls are also identical as is the case with other libc's:



~# nm -C /system/lib64/libc.so | grep geteuid$
0000000000070d58 T geteuid
~# grep geteuid$ /proc/kallsyms
0000000000000000 T sys_geteuid


RELATED: HOW TO SETUP LINUX LOGIN ENVIRONMENT ON ANDROID


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes