ioquatix
ioquatix

Reputation: 1476

Why does sudo not work when spawned inside a process group?

Using Ruby as a host language, why does the following work:

pid = Process.spawn("sudo", "ls", "-lah")
Process.wait2 pid

But this hangs with no output?

pid = Process.spawn("sudo", "ls", "-lah", pgroup: true)
Process.wait2 pid

Upvotes: 0

Views: 54

Answers (1)

ioquatix
ioquatix

Reputation: 1476

It turns out that a terminal can only have one foreground process group, which can read input and write output, and handle signals. In order to make the above work, you need to set it as the foreground process group:

pid = Process.spawn("sudo", "ls", "-lah", pgroup: true)
Termios.setpgrp($stdin, pid)
Process.wait2 pid

Upvotes: 1

Related Questions