Last active
December 21, 2015 03:29
-
-
Save voldyman/6242825 to your computer and use it in GitHub Desktop.
quick hack to check if a program is running in a termianl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// valac --pkg vte-2.90 --pkg gtk+-3.0 test.vala | |
public class Wind { | |
GLib.Pid child_pid; | |
public Wind () { | |
var w = new Gtk.Window (); | |
w.set_size_request (640,480); | |
w.destroy.connect (Gtk.main_quit); | |
var ter = new Vte.Terminal (); | |
var dir = GLib.Environment.get_current_dir (); | |
ter.fork_command_full (Vte.PtyFlags.DEFAULT, dir, { Vte.get_user_shell () }, | |
null, SpawnFlags.SEARCH_PATH, null, out child_pid); | |
ter.child_exited.connect ( () => {w.destroy (); }); | |
moni (); | |
w.add (ter); | |
w.show_all (); | |
} | |
public void moni () { | |
File f = File.new_for_path ("/proc/%d/status".printf (child_pid)); | |
print ("%s\n".printf (f.get_path ())); | |
var monitor = f.monitor_file (FileMonitorFlags.NONE, null); | |
monitor.changed.connect (changed); | |
print ("Monitoring Started \n"); | |
} | |
private void changed (File f, File? dst, FileMonitorEvent ev) { | |
print ("Changed \n"); | |
} | |
public GLib.Pid get_pid () { | |
return child_pid; | |
} | |
} | |
int main(string[] args) { | |
Gtk.init (ref args); | |
var w = new Wind(); | |
Gtk.main (); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment