File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ program example_process_kill
1717 print * , " Process running:" , running
1818
1919 ! Wait a bit before killing the process
20- call sleep(millisec= 1250 ) ! Portable subroutine for sleeping
20+ call sleep(millisec= 250 )
2121
2222 print * , " Killing the process..."
2323 call kill(process, success)
@@ -31,4 +31,7 @@ program example_process_kill
3131 ! Verify the process is no longer running
3232 running = is_running(process)
3333 print * , " Process running after kill:" , running
34+
35+ stop 0
36+
3437end program example_process_kill
Original file line number Diff line number Diff line change 88#ifdef _WIN32
99#include <windows.h>
1010#else
11+ #define _POSIX_C_SOURCE 199309L
1112#include <sys/wait.h>
1213#include <unistd.h>
1314#include <time.h>
@@ -317,15 +318,19 @@ void process_wait(float seconds)
317318 DWORD dwMilliseconds = 1000 * seconds ;
318319 Sleep (dwMilliseconds );
319320#else
320- int uSeconds = ( int ) 1.0e6 * seconds ;
321+ int ierr ;
321322
322- struct timespec t ;
323-
324- t .tv_sec = seconds ;
325- t .tv_nsec = seconds * 1000000 ;
326-
327- int ierr = nanosleep (& t , NULL );
328-
323+ struct timespec ts_remaining ;
324+ ts_remaining .tv_sec = seconds ;
325+ ts_remaining .tv_nsec = seconds * 1000000000L ;
326+
327+ do
328+ {
329+ struct timespec ts_sleep = ts_remaining ;
330+ ierr = nanosleep (& ts_sleep , & ts_remaining );
331+ }
332+ while ((EINTR == errno ) && (-1 == ierr ));
333+
329334 if (ierr != 0 ){
330335 switch (errno ){
331336 case EINTR :
You can’t perform that action at this time.
0 commit comments