Solved

Using system function to run xview

Posted on 2004-04-24
7
407 Views
Last Modified: 2006-11-17
I am writing C++ code (Linux) to display an image file using xview.  After the image is displayed for 10 seconds, how do I go about displaying the next file considering that I cannot launch xview again unless I close out the original display?

I tried this:

system("xview imageFile.pbm");
sleep(10);
system("xview imageFile2.pbm");

The only way I can shut down the application if I do a CTRL-C.  How can I capture those keystrokes and use it within the system function?  The only other way, which I was hoping I wouldn't have to do is use the system function to write out the process ids to a file then read that file and get the process id that corresponds to the xview.
0
Comment
Question by:jewee
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
You'd use 'fork()' and 'exec()' for that, e.g.

while ( true) {

    char* image = "imageFile.pbm";
    pid_t pid;

    pid = fork ();

    if ( 0 == pid) { // child process, spawn xview

        execl ( "xview", "xview", image);

    } else { // main process, wait 10s, then kill xview and restart it again

        sleep ( 10);
        kill ( pid, SIGKILL);
    }
}
0
 

Author Comment

by:jewee
Comment Utility
What header file do I need to include?
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
You'll need

    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/wait.h>
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 86

Expert Comment

by:jkr
Comment Utility
BTW, see also http://www.ecst.csuchico.edu/~beej/guide/ipc/fork.html ("A fork() Primer")
0
 

Author Comment

by:jewee
Comment Utility
Thank you for your help!  I tried your code and noticed that the execl command doesn't work.  XView does not execute.
0
 

Author Comment

by:jewee
Comment Utility
I tried entering the path of xview but it said "image not found".  For the image, I included the path but it still didn't work.

I noticed that if I use the same code you provided me, but instead of using execl, I used system, then incremented the pid after, it worked but would only launch xview once.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
>>and noticed that the execl command doesn't work.

My fault - if should be

       execl ( "xview", "xview", image, NULL);

:-(


0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now