NoahGameFrame icon indicating copy to clipboard operation
NoahGameFrame copied to clipboard

How to stop it friendly

Open yangcancai opened this issue 4 years ago • 3 comments

I try to stop NFServer friendly but it not work, The callback function "ApplictionCtrlHandler" will be HOOK some exit event for window but it do nothing work. so it is any plant to make a command plugin to control the NFServer. Thank you very much!

yangcancai avatar Jul 09 '20 10:07 yangcancai

Good question.

A friend way I knew is to catch the system signal to exit the process.

The code listed below:

void releaseYourMemory()
{
    //TODO release your memory
}

void func1()
{
    releaseYourMemory();

    exit(0);
}

void func2()
{
    releaseYourMemory();

    exit(0);
}

void func3()
{
    releaseYourMemory();

    exit(0);
}

void main()
{

    signal (SIGINT, func1);

    signal(SIGKILL, func0);

    signal(SIGSEGV, func3);

    signal(SIGTERM, func2);

    while (1)
    {
        //your loop
    }

}

Welcome to post your PR after you have tested it.

Thanks.

ketoo avatar Jul 10 '20 21:07 ketoo

This is not the right way, in *unix system only some c api can called in signal handler

发自我的iPhone

在 2020年7月11日,上午5:18,kytooooo [email protected] 写道:



Good question.

A friend way I knew is to catch the system signal to exit the process.

The code below:

` void releaseYourMemory() { //TODO release your memory }

void func1() { releaseYourMemory();

exit(0);

}

void func2() { releaseYourMemory();

exit(0);

}

void func3() { releaseYourMemory();

exit(0);

}

void main() {

signal (SIGINT, func1);

signal(SIGKILL, func0);

signal(SIGSEGV, func3);

signal(SIGTERM, func2);

while (1) { //your loop }

} `

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/ketoo/NoahGameFrame/issues/260#issuecomment-656895249, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADDQZK2GYLE3BI4DD7SHYLTR26AQXANCNFSM4OVN7NHA.

sniper00 avatar Jul 11 '20 03:07 sniper00

The routine handler must be very careful, since processing elsewhere was interrupted at some arbitrary point. POSIX has the concept of "safe function". If a signal interrupts an unsafe function, and handler calls an unsafe function, then the behavior is undefined. Safe functions are listed explicitly in the various standards. The POSIX.1-2003 list is

_Exit() _exit() abort() accept() access() aio_error() aio_return() aio_suspend() alarm() bind() cfgetispeed() cfgetospeed() cfsetispeed() cfsetospeed() chdir() chmod() chown() clock_gettime() close() connect() creat() dup() dup2() execle() execve() fchmod() fchown() fcntl() fdatasync() fork() fpathconf() fstat() fsync() ftruncate() getegid() geteuid() getgid() getgroups() getpeername() getpgrp() getpid() getppid() getsockname() getsockopt() getuid() kill() link() listen() lseek() lstat() mkdir() mkfifo() open() pathconf() pause() pipe() poll() posix_trace_event() pselect() raise() read() readlink() recv() recvfrom() recvmsg() rename() rmdir() select() sem_post() send() sendmsg() sendto() setgid() setpgid() setsid() setsockopt() setuid() shutdown() sigaction() sigaddset() sigdelset() sigemptyset() sigfillset() sigismember() signal() sigpause() sigpending() sigprocmask() sigqueue() sigset() sigsuspend() sleep() socket() socketpair() stat() symlink() sysconf() tcdrain() tcflow() tcflush() tcgetattr() tcgetpgrp() tcsendbreak() tcsetattr() tcsetpgrp() time() timer_getoverrun() timer_gettime() timer_settime() times() umask() uname() unlink() utime() wait() waitpid() write().

https://www.tutorialspoint.com/unix_system_calls/signal.htm

sniper00 avatar Jul 11 '20 04:07 sniper00