Re: [Vala] Get correct PID after sudp



On 19.04.2013 11:35, Christian Capasso wrote:
Hi,

I'm using Process.spawn_async() to launch a process that requires
administrator privileges. This function returns the PID linked to the sudo
command, which is different from the real PID of the command that I
launched.

For example, if the process launched is "dd", I get a different PID, which
corresponds to the PID assigned to the sudo command and not to "dd".

Thank you very much in advance,
Christian.
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
As far as I can tell, there's no direct way of getting at that PID. In
bash, I would do it by using the PID of the sudo command and the ps
command to get its child PIDs, like so:

$ sudo dd &
$ DD_PID=$(ps --ppid $! -o pid=)
$ echo $DD_PID

(If you're not very familiar with bash, $! is the PID of the last
launched background process, in our case, sudo.)

With that in mind, I think you could either launch and process the
output from ps directly, look into the source code of ps (
http://procps.cvs.sourceforge.net/viewvc/procps/procps/ps/ ) and see how
they get at a process' child PIDs for figuring out how to do it
yourself, or I also think it's possible to get this information from
/proc, if you're willing to go looking around in there...

Hope that helps, and that if I'm wrong, someone else can give a better
answer.

Attachment: signature.asc
Description: OpenPGP digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]