Skip to content

Commit 5629dde

Browse files
committed
O:cpu number can show its all tasks
1 parent f20fadd commit 5629dde

File tree

2 files changed

+163
-45
lines changed

2 files changed

+163
-45
lines changed

showgeneric.c

+161-45
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
int 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, }, "", "" };
6363
static struct sselection syssel;
6464

@@ -786,63 +786,93 @@ 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);
855+
856+
for (i=nsel=0; i < ncurlist; i++)
857+
{
858+
if (procsuppress(*(curlist+i), &procsel))
859+
continue;
831860

832-
if (curlist[i]->gen.state == 'E' &&
833-
suppressexit )
834-
continue;
861+
if (curlist[i]->gen.state == 'E' &&
862+
suppressexit )
863+
continue;
835864

836-
sellist[nsel++] = curlist[i];
837-
}
865+
sellist[nsel++] = curlist[i];
866+
}
838867

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;
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+
}
844874
}
845-
875+
846876
/*
847877
** sort the list in required order
848878
** (default CPU-consumption) and print the list
@@ -1750,6 +1780,73 @@ text_samp(time_t curtime, int nsecs,
17501780

17511781
firstproc = 0;
17521782
break;
1783+
1784+
/*
1785+
** focus on specific PIDs
1786+
*/
1787+
case MSELCPU:
1788+
alarm(0); /* stop the clock */
1789+
echo();
1790+
1791+
move(statline, 0);
1792+
clrtoeol();
1793+
printw("CPU Number "
1794+
"(enter=no selection): ");
1795+
1796+
scanw("%79s\n", genline);
1797+
1798+
int id_t = 0;
1799+
1800+
char *cpup = strtok(genline, ",");
1801+
1802+
while (cpup)
1803+
{
1804+
char *ep;
1805+
1806+
if (id_t >= MAXPID)
1807+
{
1808+
procsel.curcpu[id_t] = -1; // stub
1809+
1810+
statmsg = "Maximum number of"
1811+
"CPU reached!";
1812+
beep();
1813+
break;
1814+
}
1815+
1816+
procsel.curcpu[id_t] = strtol(cpup, &ep, 10);
1817+
1818+
if (procsel.curcpu[id_t] >= sstat->cpu.nrcpu)
1819+
{
1820+
procsel.curcpu[id_t] = -1; // stub
1821+
1822+
statmsg = "CPU number is too big!";
1823+
beep();
1824+
break;
1825+
}
1826+
1827+
if (*ep)
1828+
{
1829+
statmsg = "Non-numerical Pid_t!";
1830+
beep();
1831+
procsel.curcpu[0] = -1; // stub
1832+
break;
1833+
}
1834+
1835+
id_t++;
1836+
cpup = strtok(NULL, ",");
1837+
}
1838+
1839+
procsel.curcpu[id_t] = -1; // stub
1840+
1841+
noecho();
1842+
1843+
move(statline, 0);
1844+
1845+
if (interval && !paused && !rawreadflag)
1846+
alarm(3); /* set short timer */
1847+
1848+
firstproc = 0;
1849+
break;
17531850

17541851
/*
17551852
** focus on specific process/thread state
@@ -2635,6 +2732,25 @@ procsuppress(struct tstat *curstat, struct pselection *sel)
26352732
return 1;
26362733
}
26372734

2735+
/*
2736+
** check if only processes with particular PIDs
2737+
** should be shown
2738+
*/
2739+
if (sel->curcpu[0] != -1)
2740+
{
2741+
int i = 0;
2742+
2743+
while (sel->curcpu[i] != -1)
2744+
{
2745+
if (sel->curcpu[i] == curstat->cpu.curcpu)
2746+
break;
2747+
i++;
2748+
}
2749+
2750+
if (sel->curcpu[i] != curstat->cpu.curcpu)
2751+
return 1;
2752+
}
2753+
26382754
/*
26392755
** check if only processes with a particular name
26402756
** should be shown

showgeneric.h

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct pselection {
5151
uid_t userid[MAXUSERSEL];
5252

5353
pid_t pid[MAXPID];
54+
int curcpu[MAXPID];
5455

5556
char progname[64];
5657
int prognamesz;
@@ -200,6 +201,7 @@ struct sselection {
200201
#define MSELARG '/'
201202
#define MSELSTATE 'Q'
202203
#define MSELSYS 'S'
204+
#define MSELCPU 'O'
203205

204206
#define MALLPROC 'a'
205207
#define MKILLPROC 'k'

0 commit comments

Comments
 (0)