demo_system_kill Program

Uses

Contents

Source Code


Variables

Type Attributes Name Initial
character(len=80) :: argument
integer :: i
integer :: ierr
integer :: ios
integer :: pid
integer :: signal = 9

Source Code

     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