Skip to content

Commit 9873bc9

Browse files
committed
fix sleep us -> ns
1 parent 74b6ebe commit 9873bc9

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

example/system/example_process_4.f90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
3437
end program example_process_kill

src/stdlib_system_subprocess.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
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:

0 commit comments

Comments
 (0)