Find the answer to your Linux question:
Results 1 to 3 of 3
hi all how can i sleep a command that is popen("xxxxxx","r"); to two seconds. i wrote my program like this popen("xxxxxx","r"); sleep(2) popen("xxxxxx","r"); but it is not waiting for 2 ...
  1. #1
    Linux Newbie
    Join Date
    Feb 2007
    Location
    hyderabad, india
    Posts
    247

    wait for 2 seconds

    hi all
    how can i sleep a command that is popen("xxxxxx","r");
    to two seconds.
    i wrote my program like this

    popen("xxxxxx","r");
    sleep(2)
    popen("xxxxxx","r");

    but it is not waiting for 2 seconds. it is directly excuting.
    it have to wait to excute the second popen()
    how can i do?, is there any other way to wait for 2 seconds.

    please help me

    thank you in advance
    "Relationships are built on trust and communication"

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    I'm a little bit confused...

    You want to wait 2 seconds before running popen? Then simply remove the first popen.

    If you want to run popen and timeout after 2 seconds, the only way I can think of would be starting a separate thread and passing a reference to the FILE* to the starting function. Then use that separate thread to run popen, with a sleep call in the main thread. After sleep returns, you kill the thread if it's not already exited, and then you can check the status of the FILE* you passed in.

    There may be a simpler way to do the latter, but I'm not sure what it would be.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...