What is systems programming ?
System programming is a special area of programming on Unix machines.
You can group the various areas of systems software and related system calls in the following sets:
- File I/O
- Advanced file I/O
- System files and configuration
- Files and directories
- Process control
- Threads
- Server processes
- Interprocess communication
- Signal processing
- Network programming
Learning systems programming
The only way you can learn systems programming is by developing your own utilities using this book as a reference and a tutorial.
About Go
Go is a modern generic purpose open source programming language that officially announced at the end of 2009.
Spiritual fathers: Robert Griesemer , Ken Thomson, asn Rob Pike , who designed Go as a language for professional programmers who want to build reliable and robust software.
Getting ready for Go
Find your version of Go using this command:
[maxwell@MaxwellDBA ~]$
[maxwell@MaxwellDBA ~]$ go version
go version go1.10.3 gccgo (GCC) 8.5.0 20210514 (Red Hat 8.5.0-15) linux/amd64
[maxwell@MaxwellDBA ~]$
[maxwell@MaxwellDBA ~]$
[maxwell@MaxwellDBA ~]$ vi hello.go
[maxwell@MaxwellDBA ~]$ ls -ltr
total 12
-rw-rw-r-- 1 maxwell maxwell 16 Oct 10 12:47 banzhang.txt
-rwxrwxr-x 1 maxwell maxwell 265 Oct 11 07:14 maxwell_test.sh
drwxrwxr-x 5 maxwell maxwell 276 Oct 12 21:50 datas
drwxrwxr-x 3 maxwell maxwell 52 Oct 14 15:51 software
drwxr-xr-x 4 maxwell maxwell 125 Oct 14 17:05 datasets
drwxrwxr-x 5 maxwell maxwell 146 Nov 15 20:10 shelllearning
drwxrwxr-x 2 maxwell maxwell 18 Nov 15 20:53 20221115_shelllearning
-rw-rw-r-- 1 maxwell maxwell 119 Dec 7 20:55 hello.go
[maxwell@MaxwellDBA ~]$ go run hello.go
Hello World!
[maxwell@MaxwellDBA ~]$ cat hello.go
package main
import "fmt"
// This is a demonstrative comment!
func main() {
fmt.Println("Hello World!")
}
[maxwell@MaxwellDBA ~]$
Two useful Go tools
The two most useful of them are gofmt and godoc.
you can find more information about gofmt : https://golang.org/cmd/gofmt/
The following is a poorly formatted version of the hw.go program that is hard to read and understand.
[maxwell@MaxwellDBA goproject]$ cat unglyHW.go
package main
import
"fmt"
// This is a demonstrative comment!
func main(){
fmt.Println("Hello World!" )
}
[maxwell@MaxwellDBA goproject]
Processing the previous code , which is saved as unglyHW.go with gofmt, generated the following easy to read and comprehend output:
[maxwell@MaxwellDBA goproject]$ gofmt unglyHW.go
package main
import "fmt"
// This is a demonstrative comment!
func main() {
fmt.Println("Hello World!")
}
[maxwell@MaxwellDBA goproject]$
Note: Remembering that the gofmt utility does not automatically save the generated outputs is important , which means that you should either use the -w options followed by a valid filename or redirect the output of gofmt to a new file.
The godoc utility allows you to see the documentation of existing Go packages and functions. You can find more information about godoc at http://godoc.org/golang.org/x/tools/cmd/godoc
Advantages and disadvantages of Go
The list of the Go Strong features includes the following:
- easy to read and easy to understand
- The Go compiler is there to help you to print warning and error meesage that help you solve the actual problem.
- portable
- modern programming language
- support for procedural,concurrent,and distributed programming.
- support Garbage Collection(GC)
- does not have a preprocessor and does high-speed compilation.
- build web application
- uses static linking by default. which means that the produced binary files can be easily transferred.
- go can be used from the command line.
- Go keeps concepts orthogonal
The list of Go disadvantages includes the following:
- does not have direct support for object-oriented programming.
The various states of a Unix process