wxAppConsole and fork

46 views
Skip to first unread message

Сергей Коныгин

unread,
Jun 22, 2024, 2:21:18 AM (12 days ago) Jun 22
to wx-users
Hello!

I'm writing a simple linux daemon using wxAppConsole. Linux daemons usually use fork function for creating a child process. Can I use fork in OnInit() function? Is there an another way to create the child process and exit?

Vadim Zeitlin

unread,
Jun 22, 2024, 10:09:12 AM (11 days ago) Jun 22
to wx-u...@googlegroups.com
You should be able to use fork(), after all wxExecute() does it (see its
code in src/unix/utilsunx.cpp) and using it in OnInit() works fine, AFAIK.

Or you could also use wxIMPLEMENT_APP_NO_MAIN() and provide your own
main() which would fork first, before calling wxEntry() from the branch
which needs to use wx. Read the documentation of wxDISABLE_DEBUG_SUPPORT()
macro if you do this.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
https://www.tt-solutions.com/

Сергей Коныгин

unread,
Jun 23, 2024, 3:40:10 PM (10 days ago) Jun 23
to wx-users
Thanks, it works!
One more question: how can I made my own MainLoop in wxMyAppConsole that process events and constantly calls a some function like DoStep. My server must work with the socket and at the same time do some iterations of calculation. A new thread is not good idea.
суббота, 22 июня 2024 г. в 18:09:12 UTC+4, Vadim Zeitlin:

Vadim Zeitlin

unread,
Jun 23, 2024, 7:04:29 PM (10 days ago) Jun 23
to wx-u...@googlegroups.com
On Sun, 23 Jun 2024 12:40:10 -0700 (PDT) Сергей Коныгин wrote:

> One more question: how can I made my own MainLoop in wxMyAppConsole that
> process events and constantly calls a some function like DoStep.

You can use wxConsoleEventLoop in console applications and it allows you
to register sockets with it under Unix. It's not obvious it's a good idea
if you're writing something very Unix-specific, however.

Gunter Königsmann

unread,
Jun 24, 2024, 12:51:56 AM (10 days ago) Jun 24
to wx-u...@googlegroups.com
As a side note: since the arrival of systemd I had the impression that daemons tend to no more automatically fork to the background: this way it is easier to see if a daemon stops and needs to be restarted.

Сергей Коныгин

unread,
Jun 24, 2024, 1:21:18 AM (10 days ago) Jun 24
to wx-users
Can I use a console application without fork as a daemon under systemd?

понедельник, 24 июня 2024 г. в 08:51:56 UTC+4, Gunter Königsmann:

Christian Kristukat

unread,
Jun 25, 2024, 3:28:07 PM (8 days ago) Jun 25
to wx-u...@googlegroups.com
Have a look at wxTimer

--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/94f93aeb-b4e4-4df6-b67e-dd5409b8c3cen%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages