5858
5959int getresuid (uid_t * ruid , uid_t * euid , uid_t * suid );
6060
61- static struct pselection procsel = {"" , {USERSTUB , }, {0 ,},
61+ static struct pselection procsel = {"" , {USERSTUB , }, {0 ,}, { -1 ,},
6262 "" , 0 , { 0 , }, "" , 0 , { 0 , }, "" , "" };
6363static struct sselection syssel ;
6464
@@ -786,63 +786,92 @@ text_samp(time_t curtime, int nsecs,
786786 break ;
787787
788788 default :
789- threadallowed = 1 ;
790-
791- if (deviatonly && showtype != MPROCMEM &&
792- showorder != MSORTMEM )
789+ if (procsel .curcpu [0 ] != -1 )
793790 {
794- curlist = devtstat -> procactive ;
795- ncurlist = devtstat -> nprocactive ;
796- }
791+
792+ ncurlist = devtstat -> ntaskall ;
793+
794+ if (tsklist )
795+ free (tsklist ); // remove current
796+
797+ tsklist = malloc (sizeof (struct tstat * )
798+ * ncurlist );
799+ struct tstat * tall = devtstat -> taskall ;
800+
801+ int i ,j ;
802+ for (i = 0 , j = 0 ; i < ncurlist ; i ++ )
803+ {
804+ if ((tall + i )-> gen .state != 'E' && !(procsuppress (tall + i , & procsel )))
805+ {
806+ tsklist [j ++ ] = tall + i ;
807+ }
808+ }
809+
810+ curlist = tsklist ;
811+ ncurlist = j ;
812+ tlastorder = 0 ; /* new sort and zip normal view */
813+ slastorder = 0 ; /* new sort and zip now */
814+ lastsortp = & tlastorder ;
815+ }
797816 else
798817 {
799- curlist = devtstat -> procall ;
800- ncurlist = devtstat -> nprocall ;
801- }
818+ threadallowed = 1 ;
802819
803- lastsortp = & tlastorder ;
820+ if (deviatonly && showtype != MPROCMEM &&
821+ showorder != MSORTMEM )
822+ {
823+ curlist = devtstat -> procactive ;
824+ ncurlist = devtstat -> nprocactive ;
825+ }
826+ else
827+ {
828+ curlist = devtstat -> procall ;
829+ ncurlist = devtstat -> nprocall ;
830+ }
804831
805- if ( procsel .userid [0 ] == USERSTUB &&
806- !procsel .prognamesz &&
807- !procsel .container [0 ] &&
808- !procsel .states [0 ] &&
809- !procsel .argnamesz &&
810- !procsel .pid [0 ] &&
811- !suppressexit )
812- /* no selection wanted */
813- break ;
832+ lastsortp = & tlastorder ;
814833
815- /*
816- ** selection specified for tasks:
817- ** create new (worst case) pointer list if needed
818- */
819- if (sellist ) // remove previous list if needed
820- free (sellist );
834+ if ( procsel .userid [0 ] == USERSTUB &&
835+ !procsel .prognamesz &&
836+ !procsel .container [0 ] &&
837+ !procsel .states [0 ] &&
838+ !procsel .argnamesz &&
839+ !procsel .pid [0 ] &&
840+ !suppressexit )
841+ /* no selection wanted */
842+ break ;
821843
822- sellist = malloc (sizeof (struct tstat * ) * ncurlist );
844+ /*
845+ ** selection specified for tasks:
846+ ** create new (worst case) pointer list if needed
847+ */
848+ if (sellist ) // remove previous list if needed
849+ free (sellist );
823850
824- ptrverify (sellist ,
825- "Malloc failed for %d select ptrs\n" , ncurlist );
851+ sellist = malloc (sizeof (struct tstat * ) * ncurlist );
826852
827- for (i = nsel = 0 ; i < ncurlist ; i ++ )
828- {
829- if (procsuppress (* (curlist + i ), & procsel ))
830- continue ;
853+ ptrverify (sellist ,
854+ "Malloc failed for %d select ptrs\n" , ncurlist );
831855
832- if (curlist [i ]-> gen .state == 'E' &&
833- suppressexit )
834- continue ;
856+ for (i = nsel = 0 ; i < ncurlist ; i ++ )
857+ {
858+ if (procsuppress (* (curlist + i ), & procsel ))
859+ continue ;
835860
836- sellist [nsel ++ ] = curlist [i ];
837- }
861+ if (curlist [i ]-> gen .state == 'E' &&
862+ suppressexit )
863+ continue ;
838864
839- curlist = sellist ;
840- ncurlist = nsel ;
841- tlastorder = 0 ; /* new sort and zip normal view */
842- slastorder = 0 ; /* new sort and zip now */
843- lastsortp = & slastorder ;
844- }
865+ sellist [nsel ++ ] = curlist [i ];
866+ }
845867
868+ curlist = sellist ;
869+ ncurlist = nsel ;
870+ tlastorder = 0 ; /* new sort and zip normal view */
871+ slastorder = 0 ; /* new sort and zip now */
872+ lastsortp = & slastorder ;
873+ }
874+ }
846875 /*
847876 ** sort the list in required order
848877 ** (default CPU-consumption) and print the list
@@ -853,7 +882,7 @@ text_samp(time_t curtime, int nsecs,
853882 curorder = showorder ;
854883
855884 /*
856- ** determine size of list to be displayed
885+ ** determine size of list to be displayed
857886 */
858887 if (screen )
859888 plistsz = LINES - curline - 2 ;
@@ -867,13 +896,13 @@ text_samp(time_t curtime, int nsecs,
867896 if (ncurlist > 0 && plistsz > 0 )
868897 {
869898 /*
870- ** if sorting order is changed, sort again
871- */
899+ ** if sorting order is changed, sort again
900+ */
872901 if (* lastsortp != curorder )
873902 {
874903 qsort (curlist , ncurlist ,
875- sizeof (struct tstat * ),
876- procsort [(int )curorder & 0x1f ]);
904+ sizeof (struct tstat * ),
905+ procsort [(int )curorder & 0x1f ]);
877906
878907 * lastsortp = curorder ;
879908
@@ -885,13 +914,13 @@ text_samp(time_t curtime, int nsecs,
885914 int ntotal , j , t ;
886915
887916 if (deviatonly && showtype != MPROCMEM &&
888- showorder != MSORTMEM )
917+ showorder != MSORTMEM )
889918 ntotal = devtstat -> ntaskactive ;
890919 else
891920 ntotal = devtstat -> ntaskall ;
892921
893922 /*
894- ** check if existing pointer list still usable
923+ ** check if existing pointer list still usable
895924 ** if not, allocate new pointer list to be able
896925 ** to zip process list with references to threads
897926 */
@@ -902,11 +931,11 @@ text_samp(time_t curtime, int nsecs,
902931 free (tsklist ); // remove current
903932
904933 tsklist = malloc (sizeof (struct tstat * )
905- * ntotal );
934+ * ntotal );
906935
907936 ptrverify (tsklist ,
908- "Malloc failed for %d taskptrs\n" ,
909- ntotal );
937+ "Malloc failed for %d taskptrs\n" ,
938+ ntotal );
910939
911940 ntsk = ntotal ;
912941 tdeviate = deviatonly ;
@@ -917,7 +946,7 @@ text_samp(time_t curtime, int nsecs,
917946 j = ntotal ;
918947
919948 /*
920- ** zip process list with thread list
949+ ** zip process list with thread list
921950 */
922951 if (zipagain )
923952 {
@@ -927,39 +956,39 @@ text_samp(time_t curtime, int nsecs,
927956
928957 for (i = j = 0 ; i < ncurlist ; i ++ )
929958 {
930- pcur = curlist [i ];
959+ pcur = curlist [i ];
931960
932- tsklist [j ++ ] = pcur ; // take process
961+ tsklist [j ++ ] = pcur ; // take process
933962
934- n = j ; // start index of threads
963+ n = j ; // start index of threads
935964
936- for (t = pcur - tall + 1 ;
937- t < devtstat -> ntaskall &&
938- pcur -> gen .tgid &&
939- pcur -> gen .tgid ==
940- (tall + t )-> gen .tgid ;
941- t ++ )
942- {
965+ for (t = pcur - tall + 1 ;
966+ t < devtstat -> ntaskall &&
967+ pcur -> gen .tgid &&
968+ pcur -> gen .tgid ==
969+ (tall + t )-> gen .tgid ;
970+ t ++ )
971+ {
943972 if (deviatonly &&
944973 showtype != MPROCMEM &&
945- showorder != MSORTMEM )
974+ showorder != MSORTMEM )
975+ {
976+ if (!(tall + t )-> gen .wasinactive )
946977 {
947- if (!(tall + t )-> gen .wasinactive )
948- {
949978 tsklist [j ++ ] = tall + t ;
950- }
951- }
979+ }
980+ }
952981 else
953982 tsklist [j ++ ] = tall + t ;
954- }
983+ }
955984
956- if (threadsort && j - n > 0 &&
985+ if (threadsort && j - n > 0 &&
957986 curorder != MSORTMEM )
958- {
987+ {
959988 qsort (& tsklist [n ], j - n ,
960- sizeof (struct tstat * ),
961- procsort [(int )curorder & 0x1f ]);
962- }
989+ sizeof (struct tstat * ),
990+ procsort [(int )curorder & 0x1f ]);
991+ }
963992 }
964993
965994 zipagain = 0 ;
@@ -968,7 +997,6 @@ text_samp(time_t curtime, int nsecs,
968997 curlist = tsklist ;
969998 ncurlist = j ;
970999 }
971-
9721000 /*
9731001 ** print the header
9741002 ** first determine the column-header for the current
@@ -1750,6 +1778,73 @@ text_samp(time_t curtime, int nsecs,
17501778
17511779 firstproc = 0 ;
17521780 break ;
1781+
1782+ /*
1783+ ** focus on specific PIDs
1784+ */
1785+ case MSELCPU :
1786+ alarm (0 ); /* stop the clock */
1787+ echo ();
1788+
1789+ move (statline , 0 );
1790+ clrtoeol ();
1791+ printw ("CPU Number "
1792+ "(enter=no selection): " );
1793+
1794+ scanw ("%79s\n" , genline );
1795+
1796+ int id_t = 0 ;
1797+
1798+ char * cpup = strtok (genline , "," );
1799+
1800+ while (cpup )
1801+ {
1802+ char * ep ;
1803+
1804+ if (id_t >= MAXPID )
1805+ {
1806+ procsel .curcpu [id_t ] = -1 ; // stub
1807+
1808+ statmsg = "Maximum number of"
1809+ "CPU reached!" ;
1810+ beep ();
1811+ break ;
1812+ }
1813+
1814+ procsel .curcpu [id_t ] = strtol (cpup , & ep , 10 );
1815+
1816+ if (procsel .curcpu [id_t ] >= sstat -> cpu .nrcpu )
1817+ {
1818+ procsel .curcpu [id_t ] = -1 ; // stub
1819+
1820+ statmsg = "CPU number is too big!" ;
1821+ beep ();
1822+ break ;
1823+ }
1824+
1825+ if (* ep )
1826+ {
1827+ statmsg = "Non-numerical Pid_t!" ;
1828+ beep ();
1829+ procsel .curcpu [0 ] = -1 ; // stub
1830+ break ;
1831+ }
1832+
1833+ id_t ++ ;
1834+ cpup = strtok (NULL , "," );
1835+ }
1836+
1837+ procsel .curcpu [id_t ] = -1 ; // stub
1838+
1839+ noecho ();
1840+
1841+ move (statline , 0 );
1842+
1843+ if (interval && !paused && !rawreadflag )
1844+ alarm (3 ); /* set short timer */
1845+
1846+ firstproc = 0 ;
1847+ break ;
17531848
17541849 /*
17551850 ** focus on specific process/thread state
@@ -2635,6 +2730,25 @@ procsuppress(struct tstat *curstat, struct pselection *sel)
26352730 return 1 ;
26362731 }
26372732
2733+ /*
2734+ ** check if only processes with particular PIDs
2735+ ** should be shown
2736+ */
2737+ if (sel -> curcpu [0 ] != -1 )
2738+ {
2739+ int i = 0 ;
2740+
2741+ while (sel -> curcpu [i ] != -1 )
2742+ {
2743+ if (sel -> curcpu [i ] == curstat -> cpu .curcpu )
2744+ break ;
2745+ i ++ ;
2746+ }
2747+
2748+ if (sel -> curcpu [i ] != curstat -> cpu .curcpu )
2749+ return 1 ;
2750+ }
2751+
26382752 /*
26392753 ** check if only processes with a particular name
26402754 ** should be shown
0 commit comments