Here's the trick, using the -o, and L option we can search for what we need to print out
ps -opid -A
The End!
Here's the trick, using the -o, and L option we can search for what we need to print out
ps -opid -A
Oh yes, it took me time to search for this.
Here's the trick:
ps -o"%C" -p #PID
ps -opcpu -p #PID
Commonly, it's very hard for beginners to learn a new thing, especially this case, it's PowerShell. However, if you can see through its core, know the basics, and know how to search for helps or reference, it will be getting easier.
It took me about a week to learn the basis and understand the PowerShell concepts.
1. Using MSDN or MS Technet for PowerShell references.
2. Make use of some functions that provide helps.
There are two commands I use: Get-Command and Get-Help.
1. Get-Command: this function shows a list of commands being available at current session.
You can try by just typing: Get-Command, the list will show itself like this:
CommandType Name Definition ----------- ---- ---------- Alias % ForEach-Object Alias ? Where-Object Function A: Set-Location A: Alias ac Add-Content Cmdlet Add-Computer Add-Computer [-DomainName]Cmdlet Add-Content Add-Content [-Path] [-... Cmdlet Add-History Add-History [[-InputObject] Cmdlet Add-Member Add-Member [-MemberType] Cmdlet Add-PSSnapin Add-PSSnapin [-Name] [... Cmdlet Add-Type Add-Type [-TypeDefinition]
PS> Get-Command -CommandType Cmdlet
PS> Get-Help Get-Command
PS> Get-Help Get-Command -examples
PS> Get-Help Get-Command -detailed
PS> Get-Help Get-Command -full
All information about the environment variable is stored in '$env'.
When you want to retrieve info about any variable, you can follow the syntax
PS C:\> $env:windir C:\Windows PS C:\> $env:path C:\Perl\site\bin;C:\Perl\bin;C:\Program Files\ActiveState Perl Dev Kit 8.0\bin; C:\Program Files\Borland\Delphi7\Bin;C:\Program Files\Borland\Delphi7\Projects\ Bpl\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;c:\Program Files\M icrosoft SQL Server\90\Tools\binn\;C:\Web\PHP;C:\Web\PHP\ext;C:\Web\MySQL\bin;C :\Program Files\QuickTime\QTSystem\;C:\GTK\bin;C:\Program Files\Microsoft Visua l Studio 8\VC\bin;C:\Program Files\Java\jdk1.6.0_18\bin;C:\GTK2-16\bin;C:\Windo ws\System32\WindowsPowerShell\v1.0\;C:\Program Files\GTK2-Runtime\bin;C:\BC5\BI N;C:\Program Files\Nmap;C:\Program Files\Common Files\Nero\Lib\
It's a damn cool thing when you want to save something into HTML format.
Windows PowerShell provides this function through [ConvertTo-HTML] Cmdlets.
Example, if I want to save my list of current processes into HTML format
PS > Get-Process | ConvertTo-HTML | Out-File ProcessHTML.html
$format_head = "<title> PROCESS LIST </title>" $format_head += "<style> " $format_head += "TABLE { border-width:2px;border-style:solid}" $format_head += "TH {border-width:1px;border-style:solid}" $format_head += "TD {border-width:2px;border-style:solid}" $format_head += "</style>" $format_body = "<center> PROCESS LIST </center>" Get-Process | ConvertTo-HTML -head $format_head -body $format_body | Out-File processHTML.html
It's been a while since MSDN get a new face. However, I prefer the old one because it's easier to navigate to what I'm looking for.
For PowerShell reference, it's right here: http://technet.microsoft.com/en-us/library/bb978526.aspx
There're 2 ways to run your VBScript or JScript under Windows, either through CScript.exe or WScript.exe
What's the difference about those two?
- They are all almost the same, just different in the way displaying the output. While CScript.exe displays output in a Console, WScript.exe display the output in a Dialog.
Well, when you run the script, the default host will be chosen certainly. But you can switch between them.
If you want CScript.exe to be the default host
cmd> CScript //H:CScript
cmd> WScript //H:WScript
By default, you cannot execute any remote PowerShell script (extension: PS1).
However, you can set execution right to run any script on your system by calling the Set-ExecutionPolicy command
PS C:\Data> Set-ExecutionPolicy RemoteSigned Execution Policy Change The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic. Do you want to change the execution policy? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y PS C:\Data>
It's included inside Windows Management Framework RC (released on 8/13/2009).
You can download it from here:
https://connect.microsoft.com/windowsmanagement/Downloads/DownloadDetails.aspx?DownloadID=21267
But I'm not sure this is the latest.
On exponentiation, don't take the number too big like: 10 ** 99999 ... otherwise, u will get unexpected result or 1.#INF
The remainder operator doesn't apply for floating-point number, but if you do then they all will be round-off into the closest integers, then apply the operator.
In Perl, the floating-point number can be written in the form like this: 1E+01, 23.45e-02, 8.567E+32 ...
The letter 'E' or 'e' denotes the exponent.
Here the case:
my $var_1 = 11E+30; my $var_2 = 11e30; my $small_number = 0.00001; # or 1e-05 print "First case: $var_1 - $var_2 + $small_number = ".($var_1 - $var_2 + $small_number)."\n"; print "Second case: $var_1 + $small_number - $var_2 = ".($var_1 + $small_number - $var_2)."\n";Here the result:
First case: 1.1e+031 - 1.1e+031 + 1e-005 = 1e-005 Second case: 1.1e+031 + 1e-005 - 1.1e+031 = 0So how does it actually work?
my $too_small = 1e-999; print "value is $too_small\n";The result is 0 certainly, as I explained above.
I'm talking about the conditional statement IF.
Here is the definition:
IF (exp) { (statement) }Try this example:
$age = 23; if ( $age == 23 ) { print "I am 23 years-old", '\n' }Certainly perl evaluates the expression is TRUE since $age is assigned to the value '23'.
if ( $age = 23 ) { print "I am 23 years-old", '\n' }Still you've got the result printed. But how do you explain what perl does to this evaluation?
$age = 23; if ($age) { print "I am 23 years-old", '\n' }
if ( 20 = 55 ) { print "is it ok?", '\n' }
I've got no more busy right now.
Happily I can go back to my normal life and continue to update my blog with new entries, new challenges, new tricks, new tips, new tutorials ...
Hahah..so enjoy my life !