|
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,93 @@ 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); |
| 855 | + |
| 856 | + for (i=nsel=0; i < ncurlist; i++) |
| 857 | + { |
| 858 | + if (procsuppress(*(curlist+i), &procsel)) |
| 859 | + continue; |
831 | 860 |
|
832 |
| - if (curlist[i]->gen.state == 'E' && |
833 |
| - suppressexit ) |
834 |
| - continue; |
| 861 | + if (curlist[i]->gen.state == 'E' && |
| 862 | + suppressexit ) |
| 863 | + continue; |
835 | 864 |
|
836 |
| - sellist[nsel++] = curlist[i]; |
837 |
| - } |
| 865 | + sellist[nsel++] = curlist[i]; |
| 866 | + } |
838 | 867 |
|
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 | + } |
844 | 874 | }
|
845 |
| - |
| 875 | + |
846 | 876 | /*
|
847 | 877 | ** sort the list in required order
|
848 | 878 | ** (default CPU-consumption) and print the list
|
@@ -1750,6 +1780,73 @@ text_samp(time_t curtime, int nsecs,
|
1750 | 1780 |
|
1751 | 1781 | firstproc = 0;
|
1752 | 1782 | 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; |
1753 | 1850 |
|
1754 | 1851 | /*
|
1755 | 1852 | ** focus on specific process/thread state
|
@@ -2635,6 +2732,25 @@ procsuppress(struct tstat *curstat, struct pselection *sel)
|
2635 | 2732 | return 1;
|
2636 | 2733 | }
|
2637 | 2734 |
|
| 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 | + |
2638 | 2754 | /*
|
2639 | 2755 | ** check if only processes with a particular name
|
2640 | 2756 | ** should be shown
|
|
0 commit comments