For some reasons, I need invoke some system calls of the system(Linux) I checked the documentation of the 'syscall' package and couldn't find anything about it.
Then I just saw a project (https://github.com/AllenDang/w32/blob/master/kernel32.go) which wraps windows apis. I read the source code of it a bit.
It uses
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
to load the dynamic library. However, there is no documentation for function NewLazyDLL()
I am sure there should be a similar function for Linux/UNIX. Is there any one can tell me the name of the function or the way to invoke system call of Linux in Golang or load functions from libc.so ?
More details
I want to invoke system call 'daemon' or 'fork'(I want to daemonize the process) because I cannot find golang library provides them.
System calls are usually invoked by using software interrupt. A software interrupt occurs when an application program terminates or requests certain services from the operating system.
Let's inspect how to create a process in Linux A new process can be created by the fork() system call. The new process consists of a copy of the address space of the original process.
There is no daemon
style function in the Go standard library at the moment. There is an open bug about adding such a feature, but it has been deferred until after the Go 1.1 release. I would suggest reading the bug report for some of the reasons it isn't quite as simple as it might first appear.
There are other ways to run daemon processes apart from having the daemon fork itself though. Modern init daemons like Upstart and Systemd can manage such daemon processes for you, for instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With