Advertisement
Guest User

Ruby PIDs

a guest
Aug 5th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.71 KB | None | 0 0
  1. PNG_REGEX = Regexp.new(".*png")
  2.  
  3. path = File.expand_path("..")
  4. print "PATH = #{path}\n"
  5. d = Dir.new("#{path}/") #Open all png images
  6.  
  7. def is_png?(folder, filename)
  8.   return PNG_REGEX.match?(filename)
  9. end
  10.  
  11. print "Running processes: ", Process.groups.to_s
  12.  
  13. d.each { |file|
  14.   if(is_png?(path, file))
  15.     puts "Opening... #{file}"
  16.     opened_process = IO.popen("open -g -n \"#{path}/#{file}\"")
  17.     print "Parent is #{Process.pid}"
  18.     print "Child is #{opened_process.pid}" #This changes after
  19.     # calling "open"... Not sure how to get new pid
  20.    
  21.     in_str = gets #Simulate getting some input
  22.     # Close opened file after gets finishes (How??)
  23.     Process.kill("TERM", opened_process.pid)
  24.   end
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement