highest memory consuming process ?
ps -m -O %mem -u user_name | sort -nr | head -10
ps -m -O %cpu -u user_name | sort -nr | head -10
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
timothy 29217 0.0 0.0 11916 4560 pts/21 S+ 08:15 0:00 pine
root 29505 0.0 0.0 38196 2728 ? Ss Mar07 0:00 sshd: can [priv]
can 29529 0.0 0.0 38332 1904 ? S Mar07 0:00 sshd: can@notty
- USER = user owning the process
- PID = process ID of the process
- %CPU = It is the CPU time used divided by the time the process has been running.
- %MEM = ratio of the process’s resident set size to the physical memory on the machine
- VSZ = virtual memory usage of entire process (in KiB)
- RSS = resident set size, the non-swapped physical memory that a task has used (in KiB)
- TTY = controlling tty (terminal)
- STAT = multi-character process state
- START = starting time or date of the process
- TIME = cumulative CPU time
- COMMAND = command with all its arguments
In Linux the command:
ps -aux
Means show all processes for all users. You might be wondering what the x means? The x is a specifier that means 'any of the users'. So you could type this:
ps -auroot
Which displays all the root processes, or
ps -auel
which displays all the processes from user el. The technobabble in the 'man ps' page is: "ps -aux prints all processes owned by a user named 'x' as well as printing all processes that would be selected by the -a option.
batch / at
Schedule an at job using specific date and time
at time date
at 11 am may 20
at now + 1 min
at now + 1 day
$ at -f myjobs.txt now + 1 hour
at 10 am tomorrow
$ at 11:00 next month
$ at 22:00 today
$ at now + 1 week
$ at noon
modules used in perl - WWW::Mechanize, Data::Dumper, File::Path, File::remove, File::Spec - to run linux cmnds on windows
How to find third or nth maximum salary from salary table?
N minimum salary:
SELECT MIN(EmpSalary)
FROM Salary
WHERE EmpSalary IN(SELECT TOP N EmpSalary FROM Salary ORDER BY EmpSalary DESC)
for Ex: 3 minimum salary:
SELECT MIN(EmpSalary)
FROM Salary
WHERE EmpSalary IN(SELECT TOP 3 EmpSalary FROM Salary ORDER BY EmpSalary DESC)
N maximum salary:
SELECT MAX(EmpSalary)
FROM Salary
WHERE EmpSalary IN(SELECT TOP N EmpSalary FROM Salary ORDER BY EmpSalary ASC)
for Ex: 3 maximum salary:
SELECT MIN(EmpSalary)
FROM Salary
WHERE EmpSalary IN(SELECT TOP 3 EmpSalary FROM Salary ORDER BY EmpSalary ASC)
select * from (
select Emp.*,
row_number() over (order by Salary DESC) rownumb
from Employee Emp
)
where rownumb = n; /*n is nth highest salary*/
tr is an UNIX utility for translating, or deleting, or squeezing repeated characters. It will read from STDIN and write to STDOUT.
tr stands for translate.
Syntax
The syntax of tr command is:
$ tr [OPTION] SET1 [SET2]
Translation
If both the SET1 and SET2 are specified and ‘-d’ OPTION is not specified, then tr command will replace each characters in SET1 with each character in same position in SET2.
1. Convert lower case to upper case
The following tr command is used to convert the lower case to upper case
$ tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
thegeekstuff
THEGEEKSTUFF
The following command will also convert lower case to upper case
$ tr [:lower:] [:upper:]
thegeekstuff
THEGEEKSTUFF
You can also use ranges in tr. The following command uses ranges to convert lower to upper case.
2. Translate braces into parenthesis
You can also translate from and to a file. In this example we will translate braces in a file with parenthesis.
$ tr '{}' '()' < inputfile > outputfile
The above command will read each character from “inputfile”, translate if it is a brace, and write the output in “outputfile”.
3. Translate white-space to tabs
The following command will translate all the white-space to tabs
$ echo "This is for testing" | tr [:space:] '\t'
This is for testing
4. Squeeze repetition of characters using -s
In Example 3, we see how to translate space with tabs. But if there are two are more spaces present continuously, then the previous command will translate each spaces to a tab as follows.
$ echo "This is for testing" | tr [:space:] '\t'
This is for testing
We can use -s option to squeeze the repetition of characters.
$ echo "This is for testing" | tr -s [:space:] '\t'
This is for testing
Similarly you can convert multiple continuous spaces with a single space
$ echo "This is for testing" | tr -s [:space:] ' '
This is for testing
5. Delete specified characters using -d option
tr can also be used to remove particular characters using -d option.
$ echo "the geek stuff" | tr -d 't'
he geek suff
To remove all the digits from the string, use
$ echo "my username is 432234" | tr -d [:digit:]
my username is
Also, if you like to delete lines from file, you can use sed d command.
6. Complement the sets using -c option
You can complement the SET1 using -c option. For example, to remove all characters except digits, you can use the following.
$ echo "my username is 432234" | tr -cd [:digit:]
432234
7. Remove all non-printable character from a file
The following command can be used to remove all non-printable characters from a file.
$ tr -cd [:print:] < file.txt
8. Join all the lines in a file into a single line
The below command will translate all newlines into spaces and make the result as a single line.
$ tr -s '\n' ' ' < file.txt
No comments:
Post a Comment