Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I invoke system call of Linux/UNIX in golang

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.

like image 912
Janus.Le Avatar asked Mar 27 '13 06:03

Janus.Le


People also ask

What invokes a system call?

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.

Which system call is called in Linux to create a process?

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.


1 Answers

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.

like image 101
James Henstridge Avatar answered Oct 22 '22 12:10

James Henstridge