Advanced Programming in the UNIX® Environment Third Edition
SS 8.13
$ go build tsys.go
$ sudo chmod u+s tsys
$ go build printuids.go
$ ./tsys ./printuids
real uid = 501, effective uid = 501
$ sudo chmod u+s tsys
$ ./tsys ./printuids
real uid = 501, effective uid = 501
$ ll
total 7904
-rwxr-xr-x 1 ato staff 1810400 8 4 21:32 printuids
-rw-r--r-- 1 ato staff 166 8 4 21:20 printuids.go
-rwsr-xr-x 1 ato staff 2226112 8 4 21:31 tsys
-rw-r--r-- 1 ato staff 276 8 4 21:31 tsys.go
$ sudo chown root tsys
$ ll
total 7904
-rwxr-xr-x 1 ato staff 1810400 8 4 21:32 printuids
-rw-r--r-- 1 ato staff 166 8 4 21:20 printuids.go
-rwsr-xr-x 1 root staff 2226112 8 4 21:31 tsys
-rw-r--r-- 1 ato staff 276 8 4 21:31 tsys.go
$ ./tsys ./printuids
real uid = 501, effective uid = 0
$ go clean
The superuser permissions that we gave the tsys program are retained across the fork and exec that are done by system.