|
Home > Archive > Unix Programming > January 2004 > Start Acrobat Reader from my application, fork/exec/pthread???
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Start Acrobat Reader from my application, fork/exec/pthread???
|
|
| Andrea 2004-01-23, 5:02 pm |
| Hi,
I am working on a C application that has to run on Windows, Linux, Sun
and HP. This application has to start the Acrobat Reader to show some
pdf help files. On windows, it is running know, but I am not so good
on the unix process model.
The following code starts the Acrobat Reader:
void OpenHelpfile()
{
int pid, ret;
if (pid=fork())
{
return;
}
else
{
ret = execl("/home/as12242/Acrobat5/bin/acroread","acroread",NULL);
}
}
But then my problems begin:
1. the user can open a helpfile very often, and as I understand fork,
there is always created a copy of my current process - that might be
very memory intensive with the 10th help file!
2. my idea on problem 1 is to find out if acrobat is alreay running,
and only if not, I call fork. Is there something like:
if (findProcess(childPID) == false)
{
fork
exec(acroread)
}
3. and what is about pthread - might this be a alternative to fork? Is
there any useful documentation on the internet or in a book? I need
some background and concept know-how about these functions and some
good examples on how to use them. getting fork and exec running only
with man-pages is very hard!
Thanks for any help!
Andrea
| |
| Sean Burke 2004-01-23, 5:02 pm |
|
andrea@schmutt.de (Andrea) writes:
quote:
> Hi,
>
> I am working on a C application that has to run on Windows, Linux, Sun
> and HP. This application has to start the Acrobat Reader to show some
> pdf help files. On windows, it is running know, but I am not so good
> on the unix process model.
>
> The following code starts the Acrobat Reader:
>
> void OpenHelpfile()
> {
> int pid, ret;
>
> if (pid=fork())
> {
> return;
> }
> else
> {
> ret = execl("/home/as12242/Acrobat5/bin/acroread","acroread",NULL);
> }
> }
>
> But then my problems begin:
>
> 1. the user can open a helpfile very often, and as I understand fork,
> there is always created a copy of my current process - that might be
> very memory intensive with the 10th help file!
Note that the copy of your process that fork creates is
overwritten by acroread when it calls execl.
Also, it appears to me that acroread is pretty clever about
detecting when an acroread process is already running, and
handing off the document to the existing acroread process:
$ acroread ReleaseNotes.pdf &
[1] 2359
$ acroread Install.pdf &
[2] 2374
$
[2]+ Done acroread Install.pdf
$ jobs
[1]+ Running acroread ReleaseNotes.pdf &
$ ps -af | grep acroread
sean 2359 23379 3 11:13:38 pts/10 0:04 /usr/local/Acrobat5/Reader/sparcs
Note that I launch two acroreads, but the second one finishes
immediately, and only the first process remains.
quote:
> 2. my idea on problem 1 is to find out if acrobat is alreay running,
> and only if not, I call fork. Is there something like:
> if (findProcess(childPID) == false)
> {
> fork
> exec(acroread)
> }
It appears that you won't need to do that. But you will need
to do something similar in order to reap your child acroread
processes when they terminate, otherwise the children will
linger as "zombie" processes.
You will need to set a signal-handler for SIGCHLD, that calls
wait() or waitpid(). When an acroread process exits, your process
will receive the SIGCHLD signal. When the handler calls wait()
it collects the exit status of the child process, thereby allowing
the kernel to finish reclaiming the process resources.
quote:
> 3. and what is about pthread - might this be a alternative to fork?
No, pthreads won't help you here.
quote:
> Is there any useful documentation on the internet or in a book? I need
> some background and concept know-how about these functions and some
> good examples on how to use them. getting fork and exec running only
> with man-pages is very hard!
Well, the all-time favorite is:
Advanced programming in the UNIX Environment
W. Richard Stevens
Addison-Wesley
ISBN 0-201-56317-7
Another (smaller) book that I quite like, and that covers
the topics that you are concerned with from a practical
standpoint:
Practical UNIX Programming
A Guide to Concurrency, Communication and Multithreading
Kay A. Robbins & Steven Robbins
Prentice Hall
ISBN 0-13-443706-3
Hope this helps,
-SEan
| |
| Sean Burke 2004-01-23, 5:02 pm |
|
andrea@schmutt.de (Andrea) writes:
quote:
> Hi,
>
> I am working on a C application that has to run on Windows, Linux, Sun
> and HP. This application has to start the Acrobat Reader to show some
> pdf help files. On windows, it is running know, but I am not so good
> on the unix process model.
>
> The following code starts the Acrobat Reader:
>
> void OpenHelpfile()
> {
> int pid, ret;
>
> if (pid=fork())
> {
> return;
> }
> else
> {
> ret = execl("/home/as12242/Acrobat5/bin/acroread","acroread",NULL);
> }
> }
>
> But then my problems begin:
>
> 1. the user can open a helpfile very often, and as I understand fork,
> there is always created a copy of my current process - that might be
> very memory intensive with the 10th help file!
Note that the copy of your process that fork creates is
overwritten by acroread when it calls execl.
Also, it appears to me that acroread is pretty clever about
detecting when an acroread process is already running, and
handing off the document to the existing acroread process:
$ acroread ReleaseNotes.pdf &
[1] 2359
$ acroread Install.pdf &
[2] 2374
$
[2]+ Done acroread Install.pdf
$ jobs
[1]+ Running acroread ReleaseNotes.pdf &
$ ps -af | grep acroread
sean 2359 23379 3 11:13:38 pts/10 0:04 /usr/local/Acrobat5/Reader/sparcs
Note that I launch two acroreads, but the second one finishes
immediately, and only the first process remains.
quote:
> 2. my idea on problem 1 is to find out if acrobat is alreay running,
> and only if not, I call fork. Is there something like:
> if (findProcess(childPID) == false)
> {
> fork
> exec(acroread)
> }
It appears that you won't need to do that. But you will need
to do something similar in order to reap your child acroread
processes when they terminate, otherwise the children will
linger as "zombie" processes.
You will need to set a signal-handler for SIGCHLD, that calls
wait() or waitpid(). When an acroread process exits, your process
will receive the SIGCHLD signal. When the handler calls wait()
it collects the exit status of the child process, thereby allowing
the kernel to finish reclaiming the process resources.
quote:
> 3. and what is about pthread - might this be a alternative to fork?
No, pthreads won't help you here.
quote:
> Is there any useful documentation on the internet or in a book? I need
> some background and concept know-how about these functions and some
> good examples on how to use them. getting fork and exec running only
> with man-pages is very hard!
Well, the all-time favorite is:
Advanced programming in the UNIX Environment
W. Richard Stevens
Addison-Wesley
ISBN 0-201-56317-7
Another (smaller) book that I quite like, and that covers
the topics that you are concerned with from a practical
standpoint:
Practical UNIX Programming
A Guide to Concurrency, Communication and Multithreading
Kay A. Robbins & Steven Robbins
Prentice Hall
ISBN 0-13-443706-3
Hope this helps,
-SEan
| |
| Andrea 2004-01-23, 5:02 pm |
| Hi,
this helped very much, I completely forgot the zombie processes, thanks
a lot!
I already ordered the books, these are the books I always wanted and
never found...
CU Andrea
....Donīt know why Seanīs answer doesnīt appear on google? Perhaps one week later?
Sean Burke wrote:quote:
> andrea@schmutt.de (Andrea) writes:
>
>
>
>
> Note that the copy of your process that fork creates is
> overwritten by acroread when it calls execl.
>
> Also, it appears to me that acroread is pretty clever about
> detecting when an acroread process is already running, and
> handing off the document to the existing acroread process:
>
> $ acroread ReleaseNotes.pdf &
> [1] 2359
> $ acroread Install.pdf &
> [2] 2374
> $
> [2]+ Done acroread Install.pdf
> $ jobs
> [1]+ Running acroread ReleaseNotes.pdf &
> $ ps -af | grep acroread
> sean 2359 23379 3 11:13:38 pts/10 0:04 /usr/local/Acrobat5/Reader/sparcs
>
> Note that I launch two acroreads, but the second one finishes
> immediately, and only the first process remains.
>
>
>
>
> It appears that you won't need to do that. But you will need
> to do something similar in order to reap your child acroread
> processes when they terminate, otherwise the children will
> linger as "zombie" processes.
>
> You will need to set a signal-handler for SIGCHLD, that calls
> wait() or waitpid(). When an acroread process exits, your process
> will receive the SIGCHLD signal. When the handler calls wait()
> it collects the exit status of the child process, thereby allowing
> the kernel to finish reclaiming the process resources.
>
>
>
>
>
> No, pthreads won't help you here.
>
>
>
>
> Well, the all-time favorite is:
>
> Advanced programming in the UNIX Environment
> W. Richard Stevens
> Addison-Wesley
> ISBN 0-201-56317-7
>
> Another (smaller) book that I quite like, and that covers
> the topics that you are concerned with from a practical
> standpoint:
>
> Practical UNIX Programming
> A Guide to Concurrency, Communication and Multithreading
> Kay A. Robbins & Steven Robbins
> Prentice Hall
> ISBN 0-13-443706-3
>
> Hope this helps,
> -SEan
>
| |
| Andrea 2004-01-23, 5:02 pm |
| Hi,
this helped very much, I completely forgot the zombie processes, thanks
a lot!
I already ordered the books, these are the books I always wanted and
never found...
CU Andrea
....Donīt know why Seanīs answer doesnīt appear on google? Perhaps one week later?
Sean Burke wrote:quote:
> andrea@schmutt.de (Andrea) writes:
>
>
>
>
> Note that the copy of your process that fork creates is
> overwritten by acroread when it calls execl.
>
> Also, it appears to me that acroread is pretty clever about
> detecting when an acroread process is already running, and
> handing off the document to the existing acroread process:
>
> $ acroread ReleaseNotes.pdf &
> [1] 2359
> $ acroread Install.pdf &
> [2] 2374
> $
> [2]+ Done acroread Install.pdf
> $ jobs
> [1]+ Running acroread ReleaseNotes.pdf &
> $ ps -af | grep acroread
> sean 2359 23379 3 11:13:38 pts/10 0:04 /usr/local/Acrobat5/Reader/sparcs
>
> Note that I launch two acroreads, but the second one finishes
> immediately, and only the first process remains.
>
>
>
>
> It appears that you won't need to do that. But you will need
> to do something similar in order to reap your child acroread
> processes when they terminate, otherwise the children will
> linger as "zombie" processes.
>
> You will need to set a signal-handler for SIGCHLD, that calls
> wait() or waitpid(). When an acroread process exits, your process
> will receive the SIGCHLD signal. When the handler calls wait()
> it collects the exit status of the child process, thereby allowing
> the kernel to finish reclaiming the process resources.
>
>
>
>
>
> No, pthreads won't help you here.
>
>
>
>
> Well, the all-time favorite is:
>
> Advanced programming in the UNIX Environment
> W. Richard Stevens
> Addison-Wesley
> ISBN 0-201-56317-7
>
> Another (smaller) book that I quite like, and that covers
> the topics that you are concerned with from a practical
> standpoint:
>
> Practical UNIX Programming
> A Guide to Concurrency, Communication and Multithreading
> Kay A. Robbins & Steven Robbins
> Prentice Hall
> ISBN 0-13-443706-3
>
> Hope this helps,
> -SEan
>
|
|
|
|
|