Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to stop it friendly #260

Open
yangcancai opened this issue Jul 9, 2020 · 3 comments
Open

How to stop it friendly #260

yangcancai opened this issue Jul 9, 2020 · 3 comments

Comments

@yangcancai
Copy link
Contributor

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!

@ketoo
Copy link
Owner

ketoo commented Jul 10, 2020

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.

@sniper00
Copy link
Collaborator

sniper00 commented Jul 11, 2020 via email

@sniper00
Copy link
Collaborator

sniper00 commented Jul 11, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants