Parsing enviroment variables of a process at a BSD-like operating system

Olivier Duchateau duchateau.olivier at
Sun Jul 5 23:04:36 CEST 2015

2015-07-05 21:36 GMT+02:00 Stephan Haller <nomad at>:
> Hi Devs,
> I know you as being sensitive that all Xfce related applications are
> running well also at BSD-like operating systems. That's why I ask you
> for help.
> I'm the author of xfdashboard. I just implemented an application tracker
> which tries to determine which applications are running and marking the
> corresponding icon in the favourites.
> To archive it xfdashboard listens to newly opened windows, gets its
> process id and parses the enviroment variable set of the process
> at /proc/<<PID>>/environ. If it contains all needed environment
> variables and if their values are valid, then an application is
> considered to be running and marked. It is ok that this
> file /proc/<<PID>>/environ only contains the environment variables and
> name at the time the process was spawned. I do not need to know if they
> changed in the meantime.
> I know BSD is working a different way but I have no idea at all how BSD
> is working in real. So how can get this enviroment variable set under
> BSD? I really would like to use the algorithm at BSD as well because it
> is the best way I found.
> I hope you can help me.


On FreeBSD (perhaps DragonFly), you can use kinfo_getfile function
[1], which returns a pointer to an array of kinfo_file structures. It
contains kf_path member.

kern.proc.cwd is also available through sysctl(8) but I think it's
only on CURRENT (I don't have this kernel information on 10.1 and 9.3

You can also look for in source code of Tmux, especially osdep-*.c files.


> Regards,
> Stephan
> _______________________________________________
> Xfce4-dev mailing list
> Xfce4-dev at


More information about the Xfce4-dev mailing list