-
Notifications
You must be signed in to change notification settings - Fork 2
/
M_system.F90
executable file
·6051 lines (5810 loc) · 233 KB
/
M_system.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!>
!!##NAME
!! M_system(3fm) - [M_system::INTRO] Fortran interface to C system interface
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! Public objects:
!!
!! ! ENVIRONMENT
!! use M_system, only : set_environment_variable, system_unsetenv, &
!! system_putenv, system_getenv
!!
!! use M_system, only : system_intenv, system_readenv, system_clearenv
!! ! FILE SYSTEM
!! use M_system, only : system_getcwd, system_link, &
!! system_mkfifo, system_remove, system_rename, &
!! system_umask, system_unlink, fileglob, &
!! system_rmdir, system_chdir, system_mkdir, &
!! system_stat, system_isdir, system_islnk, system_isreg, &
!! system_isblk, system_ischr, system_isfifo, &
!! system_realpath, &
!! system_access, &
!! system_utime, system_time, system_sleep, &
!! system_system, &
!! system_issock, system_perm, &
!! system_stat_print, &
!! epoch_to_calendar, &
!! system_dir, &
!! system_memcpy
!!
!! !x!use M_system, only : system_getc, system_putc
!! ! ERROR PROCESSING
!! use M_system, only : system_errno, system_perror
!! ! INFO
!! use M_system, only : system_getegid, system_geteuid, system_getgid, &
!! system_gethostname, system_getpid, system_getppid, system_setsid, &
!! system_getsid, system_getuid, system_uname
!! ! SIGNALS
!! use M_system, only : system_kill,system_signal
!! ! RANDOM NUMBERS
!! use M_system, only : system_rand, system_srand
!! ! PROCESS INFORMATION
!! use M_system, only : system_cpu_time
!!
!!##DESCRIPTION
!! M_system(3fm) is a collection of Fortran procedures that call C or a
!! C wrapper using the ISO_C_BINDING interface to access system calls.
!! System calls are a special set of functions used by programs to
!! communicate directly with an operating system.
!!
!! Generally, system calls are slower than normal function calls because
!! when you make a call control is relinquished to the operating system
!! to perform the system call. In addition, depending on the nature of
!! the system call, your program may be blocked by the OS until the
!! system call has finished, thus making the execution time of your
!! program even longer.
!!
!! One rule-of-thumb that should always be followed when calling a system
!! call -- Always check the return value.
!!##ENVIRONMENT ACCESS
!! o system_putenv(3f): call putenv(3c)
!! o system_getenv(3f): function call to get_environment_variable(3f)
!! o system_unsetenv(3f): call unsetenv(3c) to remove variable
!! from environment
!! o set_environment_variable(3f): set environment variable by
!! calling setenv(3c)
!!
!! o system_initenv(3f): initialize environment table for reading
!! o system_readenv(3f): read next entry from environment table
!! o system_clearenv(3f): emulate clearenv(3c) to clear environment
!!##FILE SYSTEM
!! o system_chdir(3f): call chdir(3c) to change current
!! directory of a process
!! o system_getcwd(3f): call getcwd(3c) to get pathname of
!! current working directory
!!
!! o system_stat(3f): determine system information of file
!! by name
!! o system_stat_print(3f): print system information of filename
!! o epoch_to_calendar(3f): convert epoch time in seconds to calendar string
!!
!! o system_perm(3f): create string representing file
!! permission and type
!! o system_access(3f): determine filename access or existence
!! o system_isdir(3f): determine if filename is a directory
!! o system_islnk(3f): determine if filename is a link
!! o system_isreg(3f): determine if filename is a regular file
!! o system_isblk(3f): determine if filename is a block device
!! o system_ischr(3f): determine if filename is a character device
!! o system_isfifo(3f): determine if filename is a fifo - named pipe
!! o system_issock(3f): determine if filename is a socket
!! o system_realpath(3f): resolve a pathname
!!
!! o system_chmod(3f): call chmod(3c) to set file permission mode
!! o system_chown(3f): call chown(3c) to set file owner
!! o system_getumask(3f): call umask(3c) to get process permission mask
!! o system_setumask(3f): call umask(3c) to set process permission mask
!!
!! o system_mkdir(3f): call mkdir(3c) to create empty directory
!! o system_mkfifo(3f): call mkfifo(3c) to create a special FIFO file
!! o system_link(3f): call link(3c) to create a filename link
!!
!! o system_rename(3f): call rename(3c) to change filename
!!
!! o system_remove(3f): call remove(3c) to remove file
!! o system_rmdir(3f): call rmdir(3c) to remove empty directory
!! o system_unlink(3f): call unlink(3c) to remove a link to a file
!! o system_utime(3f): call utime(3c) to set file access and
!! modification times
!! o system_dir(3f): read name of files in specified directory
!! matching a wildcard string
!!
!! o fileglob(3f): Returns list of files using a file globbing pattern
!!##TIME
!! o system_time(3f): call time(3c)
!! o system_sleep(3f): pause specified amount of time
!!
!!##STREAM IO
!! o system_getc(3f): get a character from stdin
!! o system_putc(3f): put a character on stdout
!!##RANDOM NUMBERS
!! o system_srand(3f): call srand(3c)
!! o system_rand(3f): call rand(3c)
!!##C ERROR INFORMATION
!! o system_errno(3f): return errno(3c)
!! o system_perror(3f): call perror(3c) to display last C error message
!!##QUERIES
!! o system_geteuid(3f): call geteuid(3c)
!! o system_getuid(3f): call getuid(3c)
!! o system_getegid(3f): call getegid(3c)
!! o system_getgid(3f): call getgid(3c)
!! o system_getpid(3f): call getpid(3c)
!! o system_getppid(3f): call getppid(3c)
!! o system_gethostname(3f): get name of current host
!! o system_uname(3f): call my_uname(3c) which calls uname(3c)
!! o system_getlogin(3f): get login name
!! o system_getpwuid(3f): get login name associated with given UID
!! o system_getgrgid(3f): get group name associated with given GID
!! o system_cpu_time(3f) : get processor time in seconds using times(3c)
!!##SYSTEM COMMANDS
!! o system_system(3f): call execute_command_line(3c) outputting messages
!!
!!##FUTURE DIRECTIONS
!! A good idea of what system routines are commonly required is to refer
!! to the POSIX binding standards. (Note: IEEE 1003.9-1992 was withdrawn 6
!! February 2003.) The IEEE standard covering Fortran 77 POSIX bindings
!! is available online, though currently (unfortunately) only from
!! locations with appropriate subscriptions to the IEEE server (e.g.,
!! many university networks). For those who do have such access, the link
!! is: POSIX Fortran 77 Language Interfaces (IEEE Std 1003.9-1992) (pdf)
!!
!!##SEE ALSO
!! Some vendors provide their own way to access POSIX functions and make
!! those available as modules; for instance ...
!!
!! o the IFPORT module of Intel
!! o or the f90_* modules of NAG.
!! o There are also other compiler-independent efforts to make the
!! POSIX procedures accessible from Fortran...
!!
!! o Posix90 (doc),
!! o flib.a platform/files and directories,
!! o fortranposix.
module M_system
use,intrinsic :: iso_c_binding, only : c_float, c_int, c_char, c_ptr, c_f_pointer, c_null_char, c_null_ptr
use,intrinsic :: iso_c_binding, only : c_long, c_short, c_size_t, c_intptr_t, c_funptr
use,intrinsic :: iso_c_binding, only : c_long_long, c_funloc, c_associated
use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64 !x!, real32, real64, real128, dp=>real128
implicit none
private
! C types. Might be platform dependent
integer,parameter,public :: mode_t=int32
public :: system_rand
public :: system_srand
!-!public :: system_getc
!-!public :: system_putc
public :: system_getpid ! return process ID
public :: system_getppid ! return parent process ID
public :: system_getuid, system_geteuid ! return user ID
public :: system_getgid, system_getegid ! return group ID
public :: system_setsid
public :: system_getsid
public :: system_kill ! (pid, signal) kill process (defaults: pid=0, signal=SIGTERM)
public :: system_signal ! (signal,[handler]) install signal handler subroutine
public :: system_errno
public :: system_perror
public :: system_putenv
public :: system_getenv
public :: set_environment_variable
public :: system_unsetenv
public :: system_initenv
public :: system_readenv
public :: system_clearenv
public :: system_stat ! call stat(3c) to determine system information of file by name
public :: system_stat_print ! call stat(3f) and print principal pathname information
public :: epoch_to_calendar ! convert integer unix epoch time to calendard string
public :: system_perm ! create string representing file permission and type
public :: system_access ! determine filename access or existence
public :: system_isdir ! determine if filename is a directory
public :: system_islnk ! determine if filename is a link
public :: system_isreg ! determine if filename is a regular file
public :: system_isblk ! determine if filename is a block device
public :: system_ischr ! determine if filename is a character device
public :: system_isfifo ! determine if filename is a fifo - named pipe
public :: system_issock ! determine if filename is a socket
public :: system_realpath ! resolve pathname
public :: system_chdir
public :: system_rmdir
public :: system_remove
public :: system_rename
public :: system_mkdir
public :: system_mkfifo
public :: system_chmod
public :: system_chown
public :: system_link
public :: system_unlink
public :: system_utime
public :: system_system
public :: system_setumask
public :: system_getumask
private :: system_umask
public :: system_getcwd
public :: system_opendir
public :: system_readdir
public :: system_rewinddir
public :: system_closedir
public :: system_cpu_time
public :: system_uname
public :: system_gethostname
public :: system_getlogin
public :: system_getpwuid
public :: system_getgrgid
public :: fileglob
public :: system_alarm
public :: system_calloc
public :: system_clock
public :: system_time
public :: system_sleep
!public :: system_qsort
public :: system_realloc
public :: system_malloc
public :: system_free
public :: system_memcpy
public :: system_dir
public :: R_GRP,R_OTH,R_USR,RWX_G,RWX_O,RWX_U,W_GRP,W_OTH,W_USR,X_GRP,X_OTH,X_USR,DEFFILEMODE,ACCESSPERMS
public :: R_OK,W_OK,X_OK,F_OK ! for system_access
!===================================================================================================================================
type, bind(C) :: dirent_SYSTEMA
integer(c_long) :: d_ino
integer(c_long) :: d_off; ! __off_t, check size
integer(c_short) :: d_reclen
character(len=1,kind=c_char) :: d_name(256)
end type
type, bind(C) :: dirent_CYGWIN
integer(c_int) :: d_version
integer(c_long) :: d_ino
character(kind=c_char) :: d_type
character(kind=c_char) :: d_unused1(3)
integer(c_int) :: d_internal1
character(len=1,kind=c_char) :: d_name(256)
end type
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
interface
function system_alarm(seconds) bind(c, name="alarm")
import c_int
integer(kind=c_int), value :: seconds
integer(kind=c_int) system_alarm
end function system_alarm
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
interface
function system_calloc(nelem, elsize) bind(c, name="calloc")
import C_SIZE_T, C_INTPTR_T
integer(C_SIZE_T), value :: nelem, elsize
integer(C_INTPTR_T) system_calloc
end function system_calloc
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
interface
pure function system_clock() bind(c, name="clock")
import C_LONG
integer(C_LONG) system_clock
end function system_clock
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
! Copy N bytes of SRC to DEST, no aliasing or overlapping allowed.
! extern void *memcpy (void *dest, const void *src, size_t n);
interface
subroutine system_memcpy(dest, src, n) bind(C,name='memcpy')
import C_INTPTR_T, C_SIZE_T
INTEGER(C_INTPTR_T), value :: dest
INTEGER(C_INTPTR_T), value :: src
integer(C_SIZE_T), value :: n
end subroutine system_memcpy
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
interface
subroutine system_free(ptr) bind(c, name="free")
import C_INTPTR_T
integer(C_INTPTR_T), value :: ptr
end subroutine system_free
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
interface
function system_malloc(size) bind(c, name="malloc")
import C_SIZE_T, C_INTPTR_T
integer(C_SIZE_T), value :: size
integer(C_INTPTR_T) system_malloc
end function system_malloc
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
interface
function system_realloc(ptr, size) bind(c, name="realloc")
import C_SIZE_T, C_INTPTR_T
integer(C_INTPTR_T), value :: ptr
integer(C_SIZE_T), value :: size
integer(C_INTPTR_T) system_realloc
end function system_realloc
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
interface
function system_time(tloc) bind(c, name="time")
! tloc argument should be loaded via C_LOC from iso_c_binding
import C_PTR, C_LONG
type(C_PTR), value :: tloc
integer(C_LONG) system_time
end function system_time
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
! abstract interface
! integer(4) function compar_iface(a, b)
! import c_int
! integer, intent(in) :: a, b
!-! Until implement TYPE(*)
! integer(kind=c_int) :: compar_iface
! end function compar_iface
! end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
! interface
! subroutine system_qsort(base, nel, width, compar) bind(c, name="qsort")
! import C_SIZE_T, compar_iface
! integer :: base
!-! Until implement TYPE(*)
! integer(C_SIZE_T), value :: nel, width
! procedure(compar_iface) compar
! end subroutine system_qsort
! end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_srand(3f) - [M_system:PSEUDORANDOM] set seed for pseudo-random
!! number generator system_rand(3f)
!! (LICENSE:PD)
!!
!!##SYNOPSIS
!!
!! subroutine system_srand()
!!
!!##DESCRIPTION
!! system_srand(3f) calls the C routine srand(3c) The
!! srand(3c)/system_srand(3f) function uses its argument as the seed
!! for a new sequence of pseudo-random integers to be returned by
!! system_rand(3f)/rand(3c). These sequences are repeatable by calling
!! system_srand(3f) with the same seed value. If no seed value is
!! provided, the system_rand(3f) function is automatically seeded with
!! a value of 1.
!!
!!##EXAMPLE
!!
!! Sample program:
!!
!! program demo_system_srand
!! use M_system, only : system_srand, system_rand
!! implicit none
!! integer :: i,j
!! do j=1,2
!! call system_srand(1001)
!! do i=1,10
!! write(*,*)system_rand()
!! enddo
!! write(*,*)
!! enddo
!! end program demo_system_srand
!! expected results:
!!
!! 1512084687
!! 1329390995
!! 1874040748
!! 60731048
!! 239808950
!! 2017891911
!! 22055588
!! 1105177318
!! 347750200
!! 1729645355
!!
!! 1512084687
!! 1329390995
!! 1874040748
!! 60731048
!! 239808950
!! 2017891911
!! 22055588
!! 1105177318
!! 347750200
!! 1729645355
!!
!!##SEE ALSO
!! drand48(3c), random(3c)
! void srand_system(int *seed)
interface
subroutine system_srand(seed) bind(c,name='srand')
import c_int
integer(kind=c_int),intent(in) :: seed
end subroutine system_srand
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_kill(3f) - [M_system:SIGNALS] send a signal to a process or
!! a group of processes
!! (LICENSE:PD)
!!
!!##SYNOPSIS
!!
!! integer(kind=c_int) function system_kill(pid,sig)
!!
!! integer,intent(in) :: pid
!! integer,intent(in) :: sig
!!
!!##DESCRIPTION
!!
!! The kill() function shall send a signal to a process or a group of
!! processes specified by pid. The signal to be sent is specified by
!! sig and is either one from the list given in <signal.h> or 0. If sig
!! is 0 (the null signal), error checking is performed but no signal
!! is actually sent. The null signal can be used to check the validity
!! of pid.
!!
!! For a process to have permission to send a signal to a process
!! designated by pid, unless the sending process has appropriate
!! privileges, the real or effective user ID of the sending process
!! shall match the real or saved set-user-ID of the receiving process.
!!
!! If pid is greater than 0, sig shall be sent to the process whose
!! process ID is equal to pid.
!!
!! If pid is 0, sig shall be sent to all processes (excluding an
!! unspecified set of system processes) whose process group ID is equal
!! to the process group ID of the sender, and for which the process has
!! permission to send a signal.
!!
!! If pid is -1, sig shall be sent to all processes (excluding an
!! unspecified set of system processes) for which the process has
!! permission to send that signal.
!!
!! If pid is negative, but not -1, sig shall be sent to all processes
!! (excluding an unspecified set of system processes) whose process
!! group ID is equal to the absolute value of pid, and for which the
!! process has permission to send a signal.
!!
!! If the value of pid causes sig to be generated for the sending process,
!! and if sig is not blocked for the calling thread and if no other
!! thread has sig unblocked or is waiting in a sigwait() function for
!! sig, either sig or at least one pending unblocked signal shall be
!! delivered to the sending thread before kill() returns.
!!
!! The user ID tests described above shall not be applied when sending
!! SIGCONT to a process that is a member of the same session as the
!! sending process.
!!
!! An implementation that provides extended security controls may impose
!! further implementation-defined restrictions on the sending of signals,
!! including the null signal. In particular, the system may deny the
!! existence of some or all of the processes specified by pid.
!!
!! The kill() function is successful if the process has permission to
!! send sig to any of the processes specified by pid. If kill() fails,
!! no signal shall be sent.
!!
!!##RETURN VALUE
!!
!! Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
!! returned and errno set to indicate the error.
!!
!!##ERRORS
!! The kill() function shall fail if:
!!
!! EINVAL The value of the sig argument is an invalid or unsupported
!! signal number.
!! EPERM The process does not have permission to send the signal to
!! any receiving process.
!! ESRCH No process or process group can be found corresponding to
!! that specified by pid. The following sections are informative.
!!
!!##EXAMPLE
!!
!! Sample program:
!!
!! program demo_system_kill
!! use M_system, only : system_kill
!! use M_system, only : system_perror
!! implicit none
!! integer :: i,pid,ios,ierr,signal=9
!! character(len=80) :: argument
!!
!! do i=1,command_argument_count()
!! ! get arguments from command line
!! call get_command_argument(i, argument)
!! ! convert arguments to integers assuming they are PID numbers
!! read(argument,'(i80)',iostat=ios) pid
!! if(ios.ne.0)then
!! write(*,*)'bad PID=',trim(argument)
!! else
!! write(*,*)'kill SIGNAL=',signal,' PID=',pid
!! ! send signal SIGNAL to pid PID
!! ierr=system_kill(pid,signal)
!! ! write message if an error was detected
!! if(ierr.ne.0)then
!! call system_perror('*demo_system_kill*')
!! endif
!! endif
!! enddo
!! end program demo_system_kill
!!
!!##SEE ALSO
!! getpid(), raise(), setsid(), sigaction(), sigqueue(),
! int kill(pid_t pid, int sig);
interface
function system_kill(c_pid,c_signal) bind(c,name="kill") result(c_ierr)
import c_int
integer(kind=c_int),value,intent(in) :: c_pid
integer(kind=c_int),value,intent(in) :: c_signal
integer(kind=c_int) :: c_ierr
end function
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_errno(3f) - [M_system:ERROR_PROCESSING] C error return value
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! integer(kind=c_int) function system_errno()
!!
!!##DESCRIPTION
!! Many C routines return an error code which can be queried by errno.
!! The M_system(3fm) is primarily composed of Fortran routines that
!! call C routines. In the cases where an error code is returned vi
!! system_errno(3f) these routines will indicate it.
!!
!!##EXAMPLE
!!
!! Sample program:
!!
!! program demo_system_errno
!! use M_system, only : system_errno, system_unlink, system_perror
!! implicit none
!! integer :: stat
!! stat=system_unlink('not there/OR/anywhere')
!! if(stat.ne.0)then
!! write(*,*)'err=',system_errno()
!! call system_perror('*demo_system_errno*')
!! endif
!! end program demo_system_errno
!!
!! Typical Results:
!!
!! err= 2
!! *demo_system_errno*: No such file or directory
interface
integer(kind=c_int) function system_errno() bind (C,name="my_errno")
import c_int
end function system_errno
end interface
!-! if a macro on XLF
!-! interface system_errno
!-! function ierrno_() bind(c, name="ierrno_")
!-! import c_int
!-! integer(kind=c_int) :: ierrno_
!-! end function system_errno
!-! end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_geteuid(3f) - [M_system:QUERY] get effective UID of current
!! process from Fortran by calling geteuid(3c)
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! integer(kind=c_int) function system_geteuid()
!!
!!##DESCRIPTION
!! The system_geteuid(3f) function shall return the effective user
!! ID of the calling process. The geteuid() function shall always be
!! successful and no return value is reserved to indicate the error.
!!##EXAMPLE
!!
!! Get group ID from Fortran:
!!
!! program demo_system_geteuid
!! use M_system, only : system_geteuid
!! implicit none
!! write(*,*)'EFFECTIVE UID=',system_geteuid()
!! end program demo_system_geteuid
interface
integer(kind=c_int) function system_geteuid() bind (C,name="geteuid")
import c_int
end function system_geteuid
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_getuid(3f) - [M_system:QUERY] get real UID of current process
!! from Fortran by calling getuid(3c)
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! integer(kind=c_int) function system_getuid()
!!
!!##DESCRIPTION
!! The system_getuid(3f) function shall return the real user ID
!! of the calling process. The getuid() function shall always be
!! successful and no return value is reserved to indicate the error.
!!##EXAMPLE
!!
!! Get group ID from Fortran:
!!
!! program demo_system_getuid
!! use M_system, only : system_getuid
!! implicit none
!! write(*,*)'UID=',system_getuid()
!! end program demo_system_getuid
!!
!! Results:
!!
!! UID= 197609
interface
integer(kind=c_int) function system_getuid() bind (C,name="getuid")
import c_int
end function system_getuid
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_getegid(3f) - [M_system:QUERY] get the effective group ID (GID) of
!! current process from Fortran by calling getegid(3c)
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! integer(kind=c_int) function system_getegid()
!!##DESCRIPTION
!! The getegid() function returns the effective group ID of the
!! calling process.
!!
!!##RETURN VALUE
!! The getegid() should always be successful and no return value is
!! reserved to indicate an error.
!!
!!##ERRORS
!! No errors are defined.
!!
!!##SEE ALSO
!! getegid(), system_geteuid(), getuid(), setegid(), seteuid(), setgid(),
!! setregid(), setreuid(), setuid()
!!
!!##EXAMPLE
!!
!! Get group ID from Fortran
!!
!! program demo_system_getegid
!! use M_system, only : system_getegid
!! implicit none
!! write(*,*)'GID=',system_getegid()
!! end program demo_system_getegid
interface
integer(kind=c_int) function system_getegid() bind (C,name="getegid")
import c_int
end function system_getegid
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_getgid(3f) - [M_system:QUERY] get the real group ID (GID) of
!! current process from Fortran by calling getgid(3c)
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! integer(kind=c_int) function system_getgid()
!!##DESCRIPTION
!! The getgid() function returns the real group ID of the calling
!! process.
!!
!!##RETURN VALUE
!! The getgid() should always be successful and no return value is
!! reserved to indicate an error.
!!
!!##ERRORS
!! No errors are defined.
!!
!!##SEE ALSO
!! getegid(), system_geteuid(), getuid(), setegid(), seteuid(), setgid(),
!! setregid(), setreuid(), setuid()
!!
!!##EXAMPLE
!!
!! Get group ID from Fortran
!!
!! program demo_system_getgid
!! use M_system, only : system_getgid
!! implicit none
!! write(*,*)'GID=',system_getgid()
!! end program demo_system_getgid
interface
integer(kind=c_int) function system_getgid() bind (C,name="getgid")
import c_int
end function system_getgid
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_setsid(3f) - [M_system:QUERY] create session and set the
!! process group ID of a session leader
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! integer(kind=c_int) function system_setsid(pid)
!! integer(kind=c_int) :: pid
!!##DESCRIPTION
!! The setsid() function creates a new session, if the calling
!! process is not a process group leader. Upon return the calling
!! process shall be the session leader of this new session, shall be
!! the process group leader of a new process group, and shall have no
!! controlling terminal. The process group ID of the calling process
!! shall be set equal to the process ID of the calling process. The
!! calling process shall be the only process in the new process
!! group and the only process in the new session.
!!
!!##RETURN VALUE
!! Upon successful completion, setsid() shall return the value
!! of the new process group ID of the calling process. Otherwise,
!! it shall return -1 and set errno to indicate the error.
!!##ERRORS
!! The setsid() function shall fail if:
!!
!! o The calling process is already a process group leader
!! o the process group ID of a process other than the calling
!! process matches the process ID of the calling process.
!!##EXAMPLE
!!
!! Set SID from Fortran
!!
!! program demo_system_setsid
!! use M_system, only : system_setsid
!! implicit none
!! write(*,*)'SID=',system_setsid()
!! end program demo_system_setsid
interface
integer(kind=c_int) function system_setsid() bind (C,name="setsid")
import c_int
end function system_setsid
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_getsid(3f) - [M_system:QUERY] get the process group ID of
!! a session leader
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! integer(kind=c_int) function system_getsid(pid)
!! integer(kind=c_int) :: pid
!!##DESCRIPTION
!! The system_getsid() function obtains the process group ID of the
!! process that is the session leader of the process specified by pid.
!! If pid is 0, it specifies the calling process.
!!##RETURN VALUE
!! Upon successful completion, system_getsid() shall return
!! the process group ID of the session leader of the specified
!! process. Otherwise, it shall return -1 and set errno to indicate
!! the error.
!!##EXAMPLE
!!
!! Get SID from Fortran
!!
!! program demo_system_getsid
!! use M_system, only : system_getsid
!! use ISO_C_BINDING, only : c_int
!! implicit none
!! write(*,*)'SID=',system_getsid(0_c_int)
!! end program demo_system_getsid
interface
integer(kind=c_int) function system_getsid(c_pid) bind (C,name="getsid")
import c_int
integer(kind=c_int) :: c_pid
end function system_getsid
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_getpid(3f) - [M_system:QUERY] get PID (process ID) of current
!! process from Fortran by calling getpid(3c)
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! integer function system_getpid()
!!##DESCRIPTION
!! The system_getpid() function returns the process ID of the
!! calling process.
!!##RETURN VALUE
!! The value returned is the integer process ID. The system_getpid()
!! function shall always be successful and no return value is reserved
!! to indicate an error.
!!##EXAMPLE
!!
!! Get process PID from Fortran
!!
!! program demo_system_getpid
!! use M_system, only : system_getpid
!! implicit none
!! write(*,*)'PID=',system_getpid()
!! end program demo_system_getpid
interface
pure integer(kind=c_int) function system_getpid() bind (C,name="getpid")
import c_int
end function system_getpid
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_getppid(3f) - [M_system:QUERY] get parent process ID (PPID) of
!! current process from Fortran by calling getppid(3c)
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! integer(kind=c_int) function system_getppid()
!!##DESCRIPTION
!! The system_getppid() function returns the parent process ID of
!! the calling process.
!!
!!##RETURN VALUE
!! The system_getppid() function should always be successful and no
!! return value is reserved to indicate an error.
!!
!!##ERRORS
!! No errors are defined.
!!
!!##SEE ALSO
!! exec, fork(), getpgid(), getpgrp(), getpid(), kill(),
!! setpgid(), setsid()
!!
!!##EXAMPLE
!!
!! Get parent process PID (PPID) from Fortran
!!
!! program demo_system_getppid
!! use M_system, only : system_getppid
!! implicit none
!! write(*,*)'PPID=',system_getppid()
!! end program demo_system_getppid
interface
integer(kind=c_int) function system_getppid() bind (C,name="getppid")
import c_int
end function system_getppid
end interface
!===================================================================================================================================
!()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()!
!===================================================================================================================================
!>
!!##NAME
!! system_umask(3fp) - [M_system] set and get the file mode creation mask
!! (LICENSE:PD)
!!##SYNOPSIS
!!
!! integer(kind=c_int) function system_umask(umask_value)
!!
!!##DESCRIPTION
!! The system_umask() function shall set the file mode creation
!! mask of the process to cmask and return the previous value of the
!! mask. Only the file permission bits of cmask (see <sys/stat.h>)
!! are used; the meaning of the other bits is implementation-defined.
!!
!! The file mode creation mask of the process is used to turn off
!! permission bits in the mode argument supplied during calls to
!! the following functions:
!!
!! * open(), openat(), creat(), mkdir(), mkdirat(), mkfifo(), and mkfifoat()
!! * mknod(), mknodat()
!! * mq_open()
!! * sem_open()
!!
!! Bit positions that are set in cmask are cleared in the mode of the created file.
!!
!!##RETURN VALUE
!! The file permission bits in the value returned by umask() shall be
!! the previous value of the file mode creation mask. The state of any
!! other bits in that value is unspecified, except that a subsequent
!! call to umask() with the returned value as cmask shall leave the
!! state of the mask the same as its state before the first call,
!! including any unspecified use of those bits.
!!
!!##EXAMPLE
!!
!! Sample program:
!!
!! program demo_system_umask
!! use M_system, only : system_getumask, system_setumask
!! implicit none
!! integer value
!! integer mask
!! mask=O'002'
!! value=system_setumask(mask)
!! write(*,'(a,"octal=",O4.4," decimal=",i0)')'OLD VALUE=',value,value
!! value=system_getumask()
!! write(*,'(a,"octal=",O4.4," decimal=",i0)')'MASK=',mask,mask
!! write(*,'(a,"octal=",O4.4," decimal=",i0)')'NEW VALUE=',value,value
!! end program demo_system_umask
!!
!! Expected results:
!!
!! OLD VALUE=octal=0022 decimal=18
!! MASK=octal=0002 decimal=2
!! NEW VALUE=octal=0002 decimal=2
interface
integer(kind=c_int) function system_umask(umask_value) bind (C,name="umask")
import c_int
integer(kind=c_int),value :: umask_value
end function system_umask
end interface
!===================================================================================================================================