include: co/os.h.
#os
#os::cpunum
int cpunum();
- Returns the number of system CPU cores.
#os::cwd
fastring cwd();
- Returns path of the current working directory.
- On windows,
\
in the results will be converted to/
.
#os::daemon
void daemon();
- Put the current process to run in the background, for linux only.
#os::env
1. fastring env(const char* name);
2. bool env(const char* name, const char* value);
- 1, get value of the environment variable.
- 2, added in v2.0.2, set value of the environment variable, return true on success, otherwise false.
#os::exename
fastring exename();
- Returns name of the current process (without path).
#os::exepath
fastring exepath();
- Returns the full path of the current process.
- On windows,
\
in the results will be converted to/
.
#os::homedir
fastring homedir();
- Returns path of the home directory of the current user.
- On windows,
\
in the results will be converted to/
.
#os::pid
int pid();
- Returns the id of the current process.
#os::signal
typedef void (*sig_handler_t)(int);
sig_handler_t signal(int sig, sig_handler_t handler, int flag=0);
-
Set a handler for a signal, the parameter
sig
is the signal value, and the parameterflag
is the combination ofSA_RESTART
,SA_ONSTACK
or other options. -
The parameter
flag
is only applicable to linux/mac platforms. -
This function returns the old signal handler.
-
Example
void f(int);
os::signal(SIGINT, f); // user defined handler
os::signal(SIGABRT, SIG_DFL); // default handler
os::signal(SIGPIPE, SIG_IGN); // ignore SIGPIPE