58
58
59
59
int getresuid (uid_t * ruid , uid_t * euid , uid_t * suid );
60
60
61
- static struct pselection procsel = {"" , {USERSTUB , }, {0 ,},
61
+ static struct pselection procsel = {"" , {USERSTUB , }, {0 ,}, { -1 ,},
62
62
"" , 0 , { 0 , }, "" , 0 , { 0 , }, "" , "" };
63
63
static struct sselection syssel ;
64
64
@@ -786,63 +786,92 @@ text_samp(time_t curtime, int nsecs,
786
786
break ;
787
787
788
788
default :
789
- threadallowed = 1 ;
790
-
791
- if (deviatonly && showtype != MPROCMEM &&
792
- showorder != MSORTMEM )
789
+ if (procsel .curcpu [0 ] != -1 )
793
790
{
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
+ }
797
816
else
798
817
{
799
- curlist = devtstat -> procall ;
800
- ncurlist = devtstat -> nprocall ;
801
- }
818
+ threadallowed = 1 ;
802
819
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
+ }
804
831
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 ;
814
833
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 ;
821
843
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 );
823
850
824
- ptrverify (sellist ,
825
- "Malloc failed for %d select ptrs\n" , ncurlist );
851
+ sellist = malloc (sizeof (struct tstat * ) * ncurlist );
826
852
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 );
831
855
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 ;
835
860
836
- sellist [nsel ++ ] = curlist [i ];
837
- }
861
+ if (curlist [i ]-> gen .state == 'E' &&
862
+ suppressexit )
863
+ continue ;
838
864
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
+ }
845
867
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
+ }
846
875
/*
847
876
** sort the list in required order
848
877
** (default CPU-consumption) and print the list
@@ -853,7 +882,7 @@ text_samp(time_t curtime, int nsecs,
853
882
curorder = showorder ;
854
883
855
884
/*
856
- ** determine size of list to be displayed
885
+ ** determine size of list to be displayed
857
886
*/
858
887
if (screen )
859
888
plistsz = LINES - curline - 2 ;
@@ -867,13 +896,13 @@ text_samp(time_t curtime, int nsecs,
867
896
if (ncurlist > 0 && plistsz > 0 )
868
897
{
869
898
/*
870
- ** if sorting order is changed, sort again
871
- */
899
+ ** if sorting order is changed, sort again
900
+ */
872
901
if (* lastsortp != curorder )
873
902
{
874
903
qsort (curlist , ncurlist ,
875
- sizeof (struct tstat * ),
876
- procsort [(int )curorder & 0x1f ]);
904
+ sizeof (struct tstat * ),
905
+ procsort [(int )curorder & 0x1f ]);
877
906
878
907
* lastsortp = curorder ;
879
908
@@ -885,13 +914,13 @@ text_samp(time_t curtime, int nsecs,
885
914
int ntotal , j , t ;
886
915
887
916
if (deviatonly && showtype != MPROCMEM &&
888
- showorder != MSORTMEM )
917
+ showorder != MSORTMEM )
889
918
ntotal = devtstat -> ntaskactive ;
890
919
else
891
920
ntotal = devtstat -> ntaskall ;
892
921
893
922
/*
894
- ** check if existing pointer list still usable
923
+ ** check if existing pointer list still usable
895
924
** if not, allocate new pointer list to be able
896
925
** to zip process list with references to threads
897
926
*/
@@ -902,11 +931,11 @@ text_samp(time_t curtime, int nsecs,
902
931
free (tsklist ); // remove current
903
932
904
933
tsklist = malloc (sizeof (struct tstat * )
905
- * ntotal );
934
+ * ntotal );
906
935
907
936
ptrverify (tsklist ,
908
- "Malloc failed for %d taskptrs\n" ,
909
- ntotal );
937
+ "Malloc failed for %d taskptrs\n" ,
938
+ ntotal );
910
939
911
940
ntsk = ntotal ;
912
941
tdeviate = deviatonly ;
@@ -917,7 +946,7 @@ text_samp(time_t curtime, int nsecs,
917
946
j = ntotal ;
918
947
919
948
/*
920
- ** zip process list with thread list
949
+ ** zip process list with thread list
921
950
*/
922
951
if (zipagain )
923
952
{
@@ -927,39 +956,39 @@ text_samp(time_t curtime, int nsecs,
927
956
928
957
for (i = j = 0 ; i < ncurlist ; i ++ )
929
958
{
930
- pcur = curlist [i ];
959
+ pcur = curlist [i ];
931
960
932
- tsklist [j ++ ] = pcur ; // take process
961
+ tsklist [j ++ ] = pcur ; // take process
933
962
934
- n = j ; // start index of threads
963
+ n = j ; // start index of threads
935
964
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
+ {
943
972
if (deviatonly &&
944
973
showtype != MPROCMEM &&
945
- showorder != MSORTMEM )
974
+ showorder != MSORTMEM )
975
+ {
976
+ if (!(tall + t )-> gen .wasinactive )
946
977
{
947
- if (!(tall + t )-> gen .wasinactive )
948
- {
949
978
tsklist [j ++ ] = tall + t ;
950
- }
951
- }
979
+ }
980
+ }
952
981
else
953
982
tsklist [j ++ ] = tall + t ;
954
- }
983
+ }
955
984
956
- if (threadsort && j - n > 0 &&
985
+ if (threadsort && j - n > 0 &&
957
986
curorder != MSORTMEM )
958
- {
987
+ {
959
988
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
+ }
963
992
}
964
993
965
994
zipagain = 0 ;
@@ -968,7 +997,6 @@ text_samp(time_t curtime, int nsecs,
968
997
curlist = tsklist ;
969
998
ncurlist = j ;
970
999
}
971
-
972
1000
/*
973
1001
** print the header
974
1002
** first determine the column-header for the current
@@ -1750,6 +1778,73 @@ text_samp(time_t curtime, int nsecs,
1750
1778
1751
1779
firstproc = 0 ;
1752
1780
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 ;
1753
1848
1754
1849
/*
1755
1850
** focus on specific process/thread state
@@ -2635,6 +2730,25 @@ procsuppress(struct tstat *curstat, struct pselection *sel)
2635
2730
return 1 ;
2636
2731
}
2637
2732
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
+
2638
2752
/*
2639
2753
** check if only processes with a particular name
2640
2754
** should be shown
0 commit comments