In BASH there is a pstree command which 'draws' a tree of processes. I am wondering what is the similar function in C programming language?
A simple example would be appreciated.
In BASH there is a pstree command which 'draws' a tree of processes. I am wondering what is the similar function in C programming language?
A simple example would be appreciated.
There is no such 'function' in C. But you can easily program something that creates something alike, using execl()
/system()
calls to ps
, or by reading the /proc file system (on linux).
From there, you can get the children list of every process, and for each process of this list get their children etc.. starting from process 1 init
.
otherwise,
int main() {
system('pstree');
return 0;
}
would work :-)
If you want to reimplement it, you'd better follow Carl Norum's advice to Use The Source, Luke!