Please, can someone help me?
In a Free Pascal program and using GTK, I do the next when push a help button :
exec ('/usr/bin/gnome-help-browser', 'man:manual_page'); but the program freezes until I close the help.
The question is : how can I execute different gtk applications from Free Pascal
in a absolute independant way?.
Perhaps with FORK and WAITPID but I don't know how. Thanks.
Mailing lists / fpc-pascal / 2001-07
executing different gtk applications from FPC
12 messages · 7 people · –
- AAndreas K. Foerster 2
- Jjordi 2
- MMarco van de Voort 2
- MMichael Van Canneyt 2
- TThomas Schatzl 2
- FFernando Lozano 1
- +1 more
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
jordi wrotePlease, can someone help me? In a Free Pascal program and using GTK, I do the next when push a help button : exec ('/usr/bin/gnome-help-browser', 'man:manual_page');
The exec function from the dos unit always waits till the started application closes. If you don't want to wait, use the linux unit:
Pid:=Fork;
if Pid=0 then
execl ('/usr/bin/gnome-help-browser man:manual_page');
else
waitpid(PID,WAIT_NOWAIT) // NOWAIT means the exact syntax of execl,waitpid, see the documentation and examples
of the linux unit.Michael.
Michael Van Canneyt wrote 9 lines
I' ve changed de waitpid : waitpid (pid, nil, wnohang);If I finish first the main program and then the help (running from
a terminal), I've to use Ctrl <c> to see bash again. Otherwise I
don't see any "zombie" and seem the main program and help finishes
ok.
Excuse my poor English and thanks for your help.
The exec function from the dos unit always waits till the started application closes. If…
Michael Van Canneyt wroteThe exec function from the dos unit always waits till the started application closes. If you don't want to wait, use the linux unit:
And how can I make that with Win32?
Where can I get informations about the windows unit? Is the windows unit compatible with the linux unit?
Andreas K. Foerster wrote 9 lines
No. The windows unit is the direct translation of the Win32 API header files. It is totally incompatible with the Linux unit. The documentation for this unit is not freely available, so we cannot distribute it. On the web-site, there is a link to a copy of the win32 API help files on Borland's site. I suggest you download that.
The standard Win32 CreateProcess() function, however, does NOT wait till the application returns, so it can simply be used to create a process and continue.
Lastly: The FCL has a TProcess class, which encapsulates the linux and win32 process management, you can use that to manage processes. It allows you to specify whether the code should wait or not for the application to terminate.
Michael.
At 7/18/01 09:03 AM, you wrote:
Michael,
No. The windows unit is the direct translation of the Win32 API header files. It is totally incompatible with the Linux unit. The documentation for this unit is not freely available, so we cannot distribute it.
The lcc-win32 C compiler (http://www.cs.virginia.edu/~lcc-win32) has a large (although not absolutely complete) Win32 help file. Judging by the wording of the individual topics, it is based on the MSDN, although the structure is different. I don't know its copyright status but the fact that it comes with a free compiler suggests that it is available without restrictions. If so, you could provide a link to it on the Free Pascal site. You should contact Jacob Navia for details.
Regards,
Gabor DEAK JAHN
------------------------------------------------------------------- Gabor DEAK JAHN -- Budapest, Hungary.
WWW: www.tramontana.co.hu
E-mail:
And how can I make that with Win32? Where can I get informations about the windows unit?…
Andreas,
Show quoted text 7 lines
You should get the Win32 API help file (from Microsoft plataform SDK, or from VB Enterprise, or from Delphi...). All APIs calls are declared on the Windows unit and you can create processes, threads (use this instead of processes) and wait for them to finish if you want, or query their status. The "2" examples show how to use semaphores to implement critical regions when the pararel processes create problems with each other.
If someone from the fpc developers is reading, I'll be glad to donate these samples to the fpc team and translate/comment them if you wish. I use these examples on a computer science course.
I am sending some examples atached that show how to start processes/threads and wait for them under Linux and Windows. As the two OSes are very different on process handling, the programs will also be very different.
[]s, Fernando Lozano
Subject: Re: [fpc-pascal]executing different gtk applications from FPC
Hi,
Show quoted text 11 lines
Note that imo its not recommended to create sophisticated multithreading programs since the basic RTL (e.g. system unit) isn't threadsafe yet (afaik). Basically at least all things which implicitly or explicitly allocate memory (classes, ansistrings, ...) might cause _really_ nasty and weird things.
Even exchanging the memory management functions by OS native ones might not be sufficient (well, I've some threading code here which behaves weird when compiled with FPC but is fine with Delphi although the memory manager is exchanged; but this might be a program error and since FPC isn't supposed to be threadsafe you can't call it a bug imo)
Regards,
Thomas
Show quoted text 10 lines
Threadsafeness of FPC is being worked on by Florian in the development branch.
I have the same problem with the Delphi network suite ICS. It compiles, but doesn't work properly, probably due to threading issues.
Did you perform those tests with a recent 1.1 snapshot?
No. The windows unit is the direct translation of the Win32 API header files. It is…
Michael Van Canneyt wroteOn the web-site, there is a link to a copy of the win32 API help files on Borland's site. I suggest you download that.
Sorry, I couldn'd find that link.
Do you mean the freepascal site?
The standard Win32 CreateProcess() function, however, does NOT wait till the application returns, so it can simply be used to create a process and continue.
Thanks, that's good.
Lastly: The FCL has a TProcess class, which encapsulates the linux and win32 process management, you can use that to manage processes. It allows you to specify whether the code should wait or not for the application to terminate.
This is even better. But the FCL is also undocumented, isn't it? But okay, at least I found the example-prog. I think that's enough.
Threadsafeness of FPC is being worked on by Florian in the development branch. I have the…
From: "Marco van de Voort"
Subject: Re: [fpc-pascal]executing different gtk applications from FPC
Show quoted text 9 lines
I tried with today's snapshot again.
What is so strange about my problem is that it only screws up the exit code of the program. While multiple threads are running it works fine due to some precautions (e.g. no use of ansistrings, classes). But during the program exit (care was taken that no thread is active at that time) after the last instruction of the pascal main program it hogs the cpu for a few seconds and then exits without executing the used units' finalization procedures. According to gdb the program triggers a SIGSEGV somewhere - but no error / exception message is written to the console (e.g. the error handlers are not called; no messagebox from Windoze popping up), the program simply exits at the point the segfault occurs.
Both threads have been tested to work fine when run seperate. All access to shared global variables is protected by critical sections (using Win32 native calls of course). Likely still some ansistring stuff is used since it requires parts of the sysutils unit.
FYI, it's a simple telnet client w/o terminal emulation (otoh it's only 7k in source) for demonstration purposes.
Regards,
Thomas
Show quoted text 16 lines
Could you send me the code in private then? I'll hobby a bit around with it.
