Skip to main content
s/getuid/geteuid/ as per question
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k

User-space kernel-space communication via system calls is done in terms of memory locations and machine registers. That's way below the abstraction level of shells, which operate mainly with text strings.

That said, in bash, you can use the https://github.com/taviso/ctypes.sh plugin to get through the text-string abstraction down to C-level granularity:

$ . ctypes.sh
$ dlcall -r long getuidgeteuid
$ long:1001

For this particular operation though, it would be much simpler, more idiomatic, and more efficient to simply use bash's magic $UID variable.

$ echo $UID"$EUID" #effectively a cached getuidgeteuid call
  1001

User-space kernel-space communication via system calls is done in terms of memory locations and machine registers. That's way below the abstraction level of shells, which operate mainly with text strings.

That said, in bash, you can use the https://github.com/taviso/ctypes.sh plugin to get through the text-string abstraction down to C-level granularity:

$ . ctypes.sh
$ dlcall -r long getuid
$ long:1001

For this particular operation though, it would be much simpler, more idiomatic, and more efficient to simply use bash's magic $UID variable.

$ echo $UID #effectively a cached getuid call
  1001

User-space kernel-space communication via system calls is done in terms of memory locations and machine registers. That's way below the abstraction level of shells, which operate mainly with text strings.

That said, in bash, you can use the https://github.com/taviso/ctypes.sh plugin to get through the text-string abstraction down to C-level granularity:

$ . ctypes.sh
$ dlcall -r long geteuid
long:1001

For this particular operation though, it would be much simpler, more idiomatic, and more efficient to simply use bash's magic $UID variable.

$ echo "$EUID" #effectively a cached geteuid call
1001
Source Link
Petr Skocik
  • 29.6k
  • 18
  • 90
  • 154

User-space kernel-space communication via system calls is done in terms of memory locations and machine registers. That's way below the abstraction level of shells, which operate mainly with text strings.

That said, in bash, you can use the https://github.com/taviso/ctypes.sh plugin to get through the text-string abstraction down to C-level granularity:

$ . ctypes.sh
$ dlcall -r long getuid
$ long:1001

For this particular operation though, it would be much simpler, more idiomatic, and more efficient to simply use bash's magic $UID variable.

$ echo $UID #effectively a cached getuid call
  1001