@@ -812,7 +812,15 @@ update_info (ProcData *procdata, ProcInfo *info)
812
812
813
813
ProcInfo::cpu_times[info->pid ] = info->cpu_time = proctime.rtime ;
814
814
info->nice = procuid.nice ;
815
- info->ppid = procuid.ppid ;
815
+
816
+ // set the ppid only if one can exist
817
+ // i.e. pid=0 can never have a parent
818
+ if (info->pid > 0 ) {
819
+ info->ppid = procuid.ppid ;
820
+ }
821
+
822
+ g_assert (info->pid != info->ppid );
823
+ g_assert (info->ppid != -1 || info->pid == 0 );
816
824
817
825
/* get cgroup data */
818
826
get_process_cgroup_info (info);
@@ -822,11 +830,14 @@ update_info (ProcData *procdata, ProcInfo *info)
822
830
823
831
824
832
ProcInfo::ProcInfo (pid_t pid)
825
- : tooltip(NULL ),
833
+ : node(),
834
+ pixbuf(),
835
+ tooltip(NULL ),
826
836
name(NULL ),
827
837
arguments(NULL ),
828
838
security_context(NULL ),
829
839
pid(pid),
840
+ ppid(-1 ),
830
841
uid(-1 )
831
842
{
832
843
ProcInfo * const info = this ;
@@ -943,6 +954,8 @@ refresh_list (ProcData *procdata, const pid_t* pid_list, const guint n)
943
954
944
955
945
956
// inserts the process in the treeview if :
957
+ // - it has no parent (ppid = -1),
958
+ // ie it is for example the [kernel] on FreeBSD
946
959
// - it is init
947
960
// - its parent is already in tree
948
961
// - its parent is unreachable
@@ -956,7 +969,7 @@ refresh_list (ProcData *procdata, const pid_t* pid_list, const guint n)
956
969
// see proctable_update_list (ProcData * const procdata)
957
970
958
971
959
- if ((*it)->ppid = = 0 or in_tree.find ((*it)->ppid ) != in_tree.end ()) {
972
+ if ((*it)->ppid < = 0 or in_tree.find ((*it)->ppid ) != in_tree.end ()) {
960
973
insert_info_to_tree (*it, procdata);
961
974
in_tree.insert ((*it)->pid );
962
975
it = addition.erase (it);
@@ -1031,6 +1044,10 @@ proctable_update_list (ProcData * const procdata)
1031
1044
procdata->cpu_total_time = MAX (cpu.total - procdata->cpu_total_time_last , 1 );
1032
1045
procdata->cpu_total_time_last = cpu.total ;
1033
1046
1047
+ // FIXME: not sure if glibtop always returns a sorted list of pid
1048
+ // but it is important otherwise refresh_list won't find the parent
1049
+ std::sort (pid_list, pid_list + proclist.number );
1050
+
1034
1051
refresh_list (procdata, pid_list, proclist.number );
1035
1052
1036
1053
selection.restore (procdata->tree );
0 commit comments