Go cpuset provides functions to parse strings according to the formats specified in the Linux cpuset(7) man page. The parsed representation can then be manipulated using well known set functions (difference, intersection, ...) and formatted back to string.
- Handle all formats specified in the man page ("List" and "Mask")
- Provide an API similar to Golang's upcoming standard set container implementation (golang/go#69230)
- Make it accessible from the command-line
- Well-tested and documented
- Manage cpusets in the Linux kernel (similar to SUSE's cset command-line tool)
Install the cpuset command-line tool through
GitHub Releases:
wget -q -O /usr/local/bin/cpuset "https://github.com/vallahaye/go-cpuset/releases/latest/download/cpuset-$(uname -s)-$(uname -m)" && \
chmod +x /usr/local/bin/cpusetOr using the Go toolchain:
GOBIN=/usr/local/bin go install go.vallahaye.net/cpuset/cmd/cpuset@latestTo uninstall the cpuset command-line tool, run:
rm -f /usr/local/bin/cpusetParse two cpusets, compute the intersection and format it back to string.
// Decode str1 into a CPUSet.
s1, err := cpuset.ParseList(str1)
if err != nil {
// Do something with the error.
}
// Decode str2 into a CPUSet.
s2, err := cpuset.ParseList(str2)
if err != nil {
// Do something with the error.
}
// Compute the intersection of the two cpusets.
s := cpuset.Intersection(s1, s2)
// Encode the intersection and print the result.
fmt.Println(s.String())cpuset intersection "$STR1" "$STR2"