What is the difference between two commands, pls help to explain it.
ps -ef|sort +6|tail
oracle 55676 1 0 03:06:16 - 0:36 oracleprod (LOCAL=NO)
oracle 24876 1 0 02:52:56 - 0:40 oracleprod (LOCAL=NO)
oracle 41616 1 0 07:00:59 - 0:44 oracleprod (LOCAL=NO)
oracle 43460 1 0 02:45:05 - 0:53 oracleprod (LOCAL=NO)
oracle 25754 1 0 08:10:03 - 1:01 oracleprod (LOCAL=NO)
ps -ef|sort +5|tail
root 5440 2094 0 Nov 21 - 0:47 /usr/sbin/syslogd
root 9244 1 0 Nov 21 - 3:26 ./pcimapsvr.ip -D0
root 10782 1 0 Nov 21 - 4:41 ./pciconsvr.ip -D0
Why do both commands show different processes ? And if I keep on changing the value of 'sort +3' or reduce, the processes keeps on changing. What exactly is command all about ? Please help to explain.
You are sorting the wrong columns using both an obsolete syntax and a wrong method. No surprise random processes show up.
You'll get the top consumers that way:
ps -ef | sort -n -k8 | tail
-n means sort numerically
-k8 means sort the the eight column (cumulative execution time)
Related
I am trying to save partition value from hdfs path to a file for different tables
Tried using sed to pull last 8 digits but since partition value changes (sometimes it may be YYYYMMDD sometimes YYYYMM) trying to see if we can grep data_dt from hdfs path instead of using sed.
Code used
hadoop fs -ls <hdfs_path> | sort -k6,7 | tail -2 > partition_info.txt
partitions=$(sed -e 's,.*\(.\{8\}\)$,\1,' partition_info.txt)
echo $partitions > partition_tables.txt
Desired Output example
20200531
202005
202004
20200601
Hadoop fs -ls output looks like this
drwxr-xr-x - kmedgel kmedgego 0 2020-05-30 09:33 /km/gold/edge_gold/otsd_cmpl/data_dt=20200530
drwxr-xr-x - kmedgel kmedgego 0 2020-05-31 09:33 /km/gold/edge_gold/otsd_cmpl/data_dt=20200531
drwxr-xr-x - kmedgel kmedgego 0 2020-06-01 09:34 /km/gold/edge_gold/otsd_cmpl/data_dt=20200601
drwxr-xr-x - kmedgel kmedgego 0 2020-06-02 09:34 /km/gold/edge_gold/otsd_cmpl/data_dt=20200602
drwxr-xr-x - kmedgel kmedgego 0 2020-06-03 09:55 /km/gold/edge_gold/otsd_cmpl/data_dt=20200603
Used while loop saying notNeed for the whole statement except for the field we are looking for i.e data_dt
Answer
while IFS="=" read -r notNeed data_dt
do
{
echo $data_dt
}
done
I have a dataset like this:-
1. Sun Jul 5 00:04:01 EDT 2015
2. root 1 0 0.0 0.0 640 10372 Apr20 init [3]
3. root 2 1 0.0 0.0 0 0 Apr20 [migration/0]
And I need to filter out the timestamp from first line and add it with each message from second line.
Please help me to do this using logstash grok plugin.
is there a way to choose the columns from windows cmd command?
for example:
when i use the following command:
tasklist
i get this result:
Image Name PID Session Name Session# Mem Usage
System Idle Process 0 Services 0 12 K
System 4 Services 0 920 K
smss.exe 260 Services 0 764 K
csrss.exe 360 Services 0 3,360 K
wininit.exe 412 Services 0 4,428 K
csrss.exe 424 Console 1 10,316 K
services.exe 476 Services 0 9,116 K
winlogon.exe 500 Console 1 5,456 K
lsass.exe 512 Services 0 10,300 K
lsm.exe 540 Services 0 2,960 K
svchost.exe 648 Services 0 8,212 K
svchost.exe 724 Services 0 8,048 K
svchost.exe 796 Services 0 14,740 K
svchost.exe 848 Services 0 60,788 K
svchost.exe 884 Services 0 27,812 K
svchost.exe 1036 Services 0 9,796 K
and i need only for the first and the last column.
is there a way to desplay only the columns what i need?
tanks
This isn't perfect as the fields in tasklist vary with the length of the task names, but it may be good enough for you.
It uses a helper batch file called repl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855
tasklist|repl "^(.......................).*(.............)$" "$1 $2" m
Adjust the length of the first set of (....) to suit you.
A big helper is, that the columns have a fixed width, so you can use the following ugly one liner:
for /f "delims=" %I in ('tasklist') do #set "_=%I"&#call echo.^%_:~0,25^% ^%_:~64^%
or better this batch file:
#echo off
setlocal ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
for /f "skip=1 delims=" %%I in ('tasklist') do (
set "_=%%I"
call echo %%_:~0,25%% %%_:~64%%
)
endlocal
the call and %% syntax is my preferred style instead of DELAYEDEXPANSION which I always try to avoid, because it had some annoying side effects in my experience. Therefore I declared it bad style in our department and I'm a bit preachy about it :).
Is there a problem with the Gnuwin32 port of "find"? It sort of works on my Windows XP command line, but I get blank stares when I try using file name pattern matching function. It's from "findutils-4.2.20" package. Had to rename to "gfind.exe" so Windows wouldn't confuse with CMD.EXE's "find".
Some samples from my Windows console:
C:\PROGRA~1\GnuWin32\doc\findutils\4.2.20\findutils-4.2.20>gfind .
.
./find.chm
./find.dvi.gz
./find.GID
./find.hlp
./find.html
./find.pdf
./find.ps.gz
That works.
Again, the following works:
C:\PROGRA~1\GnuWin32\doc\findutils\4.2.20\findutils-4.2.20>gfind . -ls
1970324837321105 0 drw-rw-rw- 2 cjohns89 0 0 Jun 11:34 .
1688849860610677 128 -rw-rw-rw- 1 cjohns89 0 130729 Mar 2005 ./fin
d.chm
1688849860610679 76 -rw-rw-rw- 1 cjohns89 0 74301 Mar 2005 ./fin
d.dvi.gz
21673573207016133 20 -rw-rw-rw- 1 cjohns89 0 16826 Jun 21:05 ./fi
nd.GID
1688849860610681 152 -rw-rw-rw- 1 cjohns89 0 154036 Mar 2005 ./fin
d.hlp
1688849860610683 224 -rw-rw-rw- 1 cjohns89 0 226750 Mar 2005 ./fin
d.html
1688849860610684 372 -rw-rw-rw- 1 cjohns89 0 379300 Mar 2005 ./fin
d.pdf
1688849860610685 200 -rw-rw-rw- 1 cjohns89 0 201163 Mar 2005 ./fin
d.ps.gz
But this doesn't do squat.
C:\PROGRA~1\GnuWin32\doc\findutils\4.2.20\findutils-4.2.20>gfind . -iname '*.pdf
' -ls
It just returns to the prompt. Am I (a novice) just mistaken in my use of syntax or is there a bug?
Chuck wrote:
gfind . -iname '*.pdf ' -ls
It's better without the apostrophe, since the Windows XP command line is an MS-DOS one.
For example:
gfind . -iname *.pdf -ls
A little wordy, but this link describes the issue. The short answer is that only double-quotes actually perform quoting in Windows' cmd.exe or command.exe.
Also, bear in mind that Windows expands *.pdf in the local directory first -- see Gnuwin32 find.exe expands wildcard before performing search.
I think the key to your issue is explained here
https://stackoverflow.com/a/3996353/8543838
Does not answer your question, but in the past I too had a few issues with GnuWin32 ‘find’ and I just wanted to let you know there is an alternative, part of ezwinports (another port of gnu tools).
I also seem to remember that ezwinports’s find was much faster than GnuWin32’s.
Also, my trick to avoid renaming Gnu tools that are the same as CMD’s built in functions (such as mkdir, echo and find) is to use ‘which find’ for example in a script. Then you know you are using gnu find and don’t need to touch anything.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
On Linux, the "top" command shows a detailed but high level overview of your memory usage, showing:
Total Memory, Used Memory, Free Memory, Buffer Usage, Cache Usage, Swap size and Swap Usage.
My question is, what commands are available to show these memory usage figures in a clear and simple way? Bonus points if they're present in the "Core" install of Solaris. 'sar' doesn't count :)
Here are the basics. I'm not sure that any of these count as "clear and simple" though.
ps(1)
For process-level view:
$ ps -opid,vsz,rss,osz,args
PID VSZ RSS SZ COMMAND
1831 1776 1008 222 ps -opid,vsz,rss,osz,args
1782 3464 2504 433 -bash
$
vsz/VSZ: total virtual process size (kb)
rss/RSS: resident set size (kb, may be inaccurate(!), see man)
osz/SZ: total size in memory (pages)
To compute byte size from pages:
$ sz_pages=$(ps -o osz -p $pid | grep -v SZ )
$ sz_bytes=$(( $sz_pages * $(pagesize) ))
$ sz_mbytes=$(( $sz_bytes / ( 1024 * 1024 ) ))
$ echo "$pid OSZ=$sz_mbytes MB"
vmstat(1M)
$ vmstat 5 5
kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr rm s3 -- -- in sy cs us sy id
0 0 0 535832 219880 1 2 0 0 0 0 0 -0 0 0 0 402 19 97 0 1 99
0 0 0 514376 203648 1 4 0 0 0 0 0 0 0 0 0 402 19 96 0 1 99
^C
prstat(1M)
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
1852 martin 4840K 3600K cpu0 59 0 0:00:00 0.3% prstat/1
1780 martin 9384K 2920K sleep 59 0 0:00:00 0.0% sshd/1
...
swap(1)
"Long listing" and "summary" modes:
$ swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 256,1 16 1048560 1048560
$ swap -s
total: 42352k bytes allocated + 20192k reserved = 62544k used, 607672k available
$
top(1)
An older version (3.51) is available on the Solaris companion CD from Sun, with the disclaimer that this is "Community (not Sun) supported".
More recent binary packages available from sunfreeware.com or blastwave.org.
load averages: 0.02, 0.00, 0.00; up 2+12:31:38 08:53:58
31 processes: 30 sleeping, 1 on cpu
CPU states: 98.0% idle, 0.0% user, 2.0% kernel, 0.0% iowait, 0.0% swap
Memory: 1024M phys mem, 197M free mem, 512M total swap, 512M free swap
PID USERNAME LWP PRI NICE SIZE RES STATE TIME CPU COMMAND
1898 martin 1 54 0 3336K 1808K cpu 0:00 0.96% top
7 root 11 59 0 10M 7912K sleep 0:09 0.02% svc.startd
sar(1M)
And just what's wrong with sar? :)
# echo ::memstat | mdb -k
Page Summary Pages MB %Tot
------------ ---------------- ---------------- ----
Kernel 7308 57 23%
Anon 9055 70 29%
Exec and libs 1968 15 6%
Page cache 2224 17 7%
Free (cachelist) 6470 50 20%
Free (freelist) 4641 36 15%
Total 31666 247
Physical 31256 244
"top" is usually available on Solaris.
If not then revert to "vmstat" which is available on most UNIX system.
It should look something like this (from an AIX box)
vmstat
System configuration: lcpu=4 mem=12288MB ent=2.00
kthr memory page faults cpu
----- ----------- ------------------------ ------------ -----------------------
r b avm fre re pi po fr sr cy in sy cs us sy id wa pc ec
2 1 1614644 585722 0 0 1 22 104 0 808 29047 2767 12 8 77 3 0.45 22.3
the colums "avm" and "fre" tell you the total memory and free memery.
a "man vmstat" should get you the gory details.
Top can be compiled from sources or downloaded from sunfreeware.com. As previously posted, vmstat is available (I believe it's in the core install?).
The command free is nice. Takes a short while to understand the "+/- buffers/cache", but the idea is that cache and buffers doesn't really count when evaluating "free", as it can be dumped right away. Therefore, to see how much free (and used) memory you have, you need to remove the cache/buffer usage - which is conveniently done for you.