Tuesday, October 31, 2017

Cygwin vs. MinGW

As a simplification, it's like this:
  • Compile something in Cygwin and you are compiling it for Cygwin.
  • Compile something in MinGW and you are compiling it for Windows.
About Cygwin
The purpose of Cygwin is to make porting *nix-based applications to Windows much easier, by emulating many of the small details that Unix-based operating systems provide, and are documented by the POSIX standards. If your application assumes that it can use Unix feature such as pipes, Unix-style file and directory access, and so forth, then you can compile it in Cygwin and Cygwin itself will act as a compatibility layer around your application, so that many of these Unix-specific paradigms can continue to be used with little or no modification to your application.
If you want to compile something for Cygwin and distribute that resulting application, you must also distribute the Cygwin run-time environment (provided by cygwin1.dll) along with it, and this has implications for what types of software license you may use.
About MinGW
MinGW is a Windows port of the GNU compiler tools, such as GCC, Make, Bash, and so on. It does not attempt to emulate or provide comprehensive compatibility with Unix, but instead it provides the minimum necessary environment to use GCC (the GNU compiler) and a small number of other tools on Windows. It does not have a Unix emulation layer like Cygwin, but as a result your application needs to specifically be programmed to be able to run in Windows, which may mean significant alteration if it was created to rely on being run in a standard Unix environment and uses Unix-specific features such as those mentioned earlier. By default, code compiled in MinGW's GCC will compile to a native Windows X86 target, including .exe and .dll files, though you could also cross-compile with the right settings. MinGW is an open-source alternative to Microsoft Visual C++ compiler and its associated linking/make tools.
Considerably sophisticated cross-platform frameworks exist which make the task of porting applications to various operating systems easily - for example the Qt framework is a popular framework for cross-platform applications. If you use such a framework from the start, you can not only reduce your headaches when it comes time to port to another platform but you can use the same graphical widgets - windows, menus and controls - across all platforms if you're writing a GUI app.

Monday, October 23, 2017

How to compile and install programs from source

Normally, the project will have a website with instructions for how to build and install it. Google for that first.
For the most part you will do either:
  1. Download a tarball (tar.gz or tar.bz2 file), which is a release of a specific version of the source code
  2. Extract the tarball with a command like tar zxvf myapp.tar.gz for a gzipped tarball or tar jxvf myapp.tar.bz2 for a bzipped tarball
  3. cd into the directory created above
  4. run ./configure && make && sudo make install
Or:
  1. Use git or svn or whatever to pull the latest source code from their official source repository
  2. cd into the directory created above
  3. run ./autogen.sh && make && sudo make install
Both configure and autogen.sh will accept a --prefix argument to specify where the software is installed. I recommend checking out Where should I put software I compile myself? for advice on the best place to install custom-built software.

Example syntax for Secure Copy (scp)

What is Secure Copy?

scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.

Examples

Copy the file "foobar.txt" from a remote host to the local host

    $ scp your_username@remotehost.edu:foobar.txt /some/local/directory

Copy the file "foobar.txt" from the local host to a remote host

    $ scp foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy the directory "foo" from the local host to a remote host's directory "bar"

    $ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu"

    $ scp your_username@rh1.edu:/some/remote/directory/foobar.txt \
    your_username@rh2.edu:/some/remote/directory/

Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host

    $ scp foo.txt bar.txt your_username@remotehost.edu:~

Copy the file "foobar.txt" from the local host to a remote host using port 2264

    $ scp -P 2264 foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy multiple files from the remote host to your current directory on the local host

    $ scp your_username@remotehost.edu:/some/remote/directory/\{a,b,c\} .
    $ scp your_username@remotehost.edu:~/\{foo.txt,bar.txt\} .

scp Performance

By default scp uses the Triple-DES cipher to encrypt the data being sent. Using the Blowfish cipher has been shown to increase speed. This can be done by using option -c blowfish in the command line.
    $ scp -c blowfish some_file your_username@remotehost.edu:~
It is often suggested that the -C option for compression should also be used to increase speed. The effect of compression, however, will only significantly increase speed if your connection is very slow. Otherwise it may just be adding extra burden to the CPU. An example of using blowfish and compression:
    $ scp -c blowfish -C local_file your_username@remotehost.edu:~

Contributions

Thanks Stewart Macleod for port example.

Saturday, October 21, 2017

How to install or upgrade an RPM package?

Environment

  • Red Hat Enterprise Linux

Issue

  • How to install or upgrade an RPM package ?
  • How to upgrade rpm package ?

Resolution

NOTE: Using yum command should be better than rpm command after Red Hat Enterprise Linux 5, since it can update local yum database properly.
In order to install an RPM package you must first have the RPM package you are trying to install on your system. Many people will download RPM packages from a website and of course, Customer Portal provides all the RPM packages included in our distributions.
There are two main options of rpm command that are used to install or upgrade RPM packages:
  • -i is used to install a new package. Always use this for kernel installations and upgrades just in case.
  • -U is used to upgrade an RPM package but will also install a package if it does not exist in the RPM database.
Usage and additional options can be found in the RPM man page. Type man rpm from the command line. Here is some information about the -i and -U flags:
INSTALL AND UPGRADE OPTIONS
    The general form of an rpm install command is

    rpm {-i|--install} [install-options] PACKAGE_FILE ...

    This installs a new package.

    The general form of an rpm upgrade command is

    rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...

    This install the package or upgrades the package currently installed  to  a  newer
    version.   This  is the same as install, except all other version(s) of
    the package are removed after the new package is installed.
Examples:
Note: These examples assume the packages are in a directory on your system. The below RPM commands are executed in the current working directory where the new RPM files reside.
  • To install an RPM package, we use of the -i flag. As mentioned before, you use this flag when you are installing a kernel RPM. In this case, you will want to leave your old kernel in place, at least temporarily, in case the new kernel does not boot. In this example, we first check to see the names of the new RPM packages with the ls command. Then we query the RPM database to see which kernel packages are already installed. You do not need to include the version number in the query, but the usage is: rpm -q <package name>. We can install the RPM package with the following command: rpm -ivh <package name>. Note the -v option will show verbose output and the -h will show the hash marks, which represents action of the progress of the RPM upgrade. Lastly, we run another RPM query to verify the package will be available.
# ls
kernel-2.4.21-15.0.3.EL.i686.rpm
kernel-smp-2.4.21-15.0.3.EL.i686.rpm
# rpm -q kernel; rpm -q kernel-smp
kernel-2.4.21-4.0.1.EL
kernel-2.4.21-15.0.2.EL
kernel-smp-2.4.21-4.0.1.EL
kernel-smp-2.4.21-15.0.2.EL
# rpm -ivh kernel-2.4.21-15.0.3.EL.i686.rpm
Preparing...                ########################################### [100%]
   1:kernel                 ########################################### [100%]
# rpm -ivh kernel-smp-2.4.21-15.0.3.EL.i686.rpm
Preparing...                ########################################### [100%]
   1:kernel-smp             ########################################### [100%]
# rpm -q kernel; rpm -q kernel-smp
kernel-2.4.21-4.0.1.EL
kernel-2.4.21-15.0.2.EL
kernel-2.4.21-15.0.3.EL
kernel-smp-2.4.21-4.0.1.EL
kernel-smp-2.4.21-15.0.2.EL
kernel-smp-2.4.21-15.0.3.EL
  • To upgrade an RPM package, we use of the -U flag. In this example, we verify the new package name with the ls command. Then we will run an RPM query to see if the package we want to install exists in the RPM database, rpm -q <package name>. Next, we execute the RPM installation with the following command: rpm -Uvh <package name>. Note the -v option will show verbose output and the -h will show the hash marks, which represents action of the progress of the RPM upgrade. Lastly, we run another RPM query to verify the package will be available.
# ls
httpd-2.0.46-32.ent.3.i386.rpm
mod_ssl-2.0.46-32.ent.3.i386.rpm
# rpm -q httpd; rpm -q mod_ssl
httpd-2.0.46-32.ent
mod_ssl-2.0.46-32.ent
# rpm -Uvh httpd-2.0.46-32.ent.3.i386.rpm mod_ssl-2.0.46-32.ent.3.i386.rpm
Preparing...                ########################################### [100%]
   1:httpd                  ########################################### [ 50%]
   2:mod_ssl                ########################################### [100%]
# rpm -q httpd; rpm -q mod_ssl
httpd-2.0.46-32.ent.3
mod_ssl-2.0.46-32.ent.3
Note: The httpd and mod_ssl needed to be installed at the same time because of dependency issues. If you try to install one without the other, you would get an error similar to the following:
# rpm -Uvh httpd-2.0.46-32.ent.3.i386.rpm
error: Failed dependencies:
        httpd = 2.0.46-32.ent is needed by (installed) mod_ssl-2.0.46-32.ent
Note: Alternatively, if you have registered your machine via Customer Portal, you may refer How do I apply package updates from the Red Hat Network? to install/update packages.
Note: Red Hat Network (RHN) was integrated into Customer Portal, Welcome to the New
Red Hat Network!

Upgrades in Red Hat Enterprise Linux 4
Currently it is possible to find only errata updates for RHEL 4. The packages can be downloaded and installed manually but it is not possible to use the command up2date. Also, the downloads work only for the RHEL 4.9 version. Other updates than errata are not available as we are approaching the the RHEL 4 end of life.
For more information on the end of life of RHEL 4 follow this link:
When is the end of life (EOL) support on RHEL 4?
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

RPM package: install, upgrade, erase

Install a RPM package


Code: [ Select ]
rpm –ivh packagename.rpm


Upgrade a RPM package


Code: [ Select ]
rpm –Uvh packagename.rpm


Verify a RPM package was installed


Code: [ Select ] [ Line Numbers Off ]
  1. rpm -qa | grep packagename
  2. locate packagename


Create a tar file


Code: [ Select ]
tar –cvf myfiles.tar mydir/


Create a tar file gzipped


Similar to above, but add a z for creating .tgz (.tar.gz) files)
Code: [ Select ]
tar –cvzf myfiles.tgz mydir/


Standard install from source


A common way to install software from source will be done similarly to the below:
Code: [ Select ] [ Line Numbers Off ]
  1. tar –xvzf Apackage.tar.gz
  2. cd Apackage
  3. ./configure
  4. make
  5. make install

Google Yum Repository Examples

The examples are shown enabled by default. Change to enabled=0 to leave disabled unless explicitly enabled.
/etc/yum.repos.d/google.repo
[google]
name=Google - $basearch
baseurl=http://dl.google.com/linux/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
/etc/yum.repos.d/google-chrome.repo
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
/etc/yum.repos.d/google-earth.repo
[google-earth]
name=google-earth
baseurl=http://dl.google.com/linux/earth/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

install chrome on centos

Google Chrome is a freeware web browser developed by Google Inc. Google Chrome team proudly announced the release of Google Chrome 60 on August 2, 2017.
The actual version is 60.0.3112.90 for Linux and Mac OS X/Windows operating system. This new version bundled with a number of exciting fixes, features and improvements.
If you would like to know more other cool features of this release, please visit at Google’s Chrome Features.
In this tutorial we will show you how we have practically installed Google Chrome 60 browser in one of our CentOS 7.3 server using Google’s own repository with Yum tool and a third party script from Richard Lloyd, which installs latest chrome version on older RHEL/CentOS and Fedora versions.
Important: Google Chrome support for all 32-bit Linux distributions is deprecated from March, 2016.
By using Google’s official repository you will keep your Chrome browser up-to-date.
# yum update google-chrome-stable
However, same instructions should also work on RHEL 7.x/6.x, CentOS 7.x/6.x and Fedora 26-20 versions as well.

Step 1: Enable Google YUM repository

Create a file called /etc/yum.repos.d/google-chrome.repo and add the following lines of code to it.
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

Step 2: Installing Chrome Web Browser

First, check whether the latest version available from the Google’s own repository using following yum command.
# yum info google-chrome-stable
Sample Output
Check Google Chrome Package Info
Loading mirror speeds from cached hostfile
* base: centos.myfahim.com
* epel: ir.mirror.rasanegar.com
* extras: centos.myfahim.com
* remi-safe: ftp.arnes.si
* rpmforge: mirrors.neusoft.edu.cn
* updates: centos.myfahim.com
adobe-linux-x86_64                                                                                                                                                      3/3
google-chrome                                                                                                                                                           3/3
Available Packages
Name        : google-chrome-stable
Arch        : x86_64
Version     : 60.0.3112.90
Release     : 1
Size        : 54 M
Repo        : google-chrome
Summary     : Google Chrome
URL         : https://chrome.google.com/
License     : Multiple, see https://chrome.google.com/
Description : The web browser from Google
: 
: Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier.
Do you see the highlighted output in the above, that clearly telling that the latest version of chrome is available from repository. So, let’s install it using yum command as shown below, which will automatically install all needed dependencies.
# yum install google-chrome-stable
Sample Output
Install Google Chrome in Linux
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager, versionlock
Loading mirror speeds from cached hostfile
* base: mirror.fibergrid.in
* epel: ftp.riken.jp
* extras: mirrors.viethosting.vn
* remi-safe: ftp.arnes.si
* rpmforge: mirror.team-cymru.org
* updates: mirror.fibergrid.in
Resolving Dependencies
--> Running transaction check
---> Package google-chrome-stable.x86_64 0:60.0.3112.90 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================================================
Package                    Arch                     Version                 Repository                     Size
======================================================================================================================================================================
Installing:
google-chrome-stable      x86_64                  60.0.3112.90          google-chrome                    54 M
Transaction Summary
======================================================================================================================================================================
Install  1 Package
Total download size: 54 M
Installed size: 205 M
Is this ok [y/d/N]: y
Update : Sadly, the Google Chrome browser no longer supports the most famous commercial distribution RHEL 6.x and its free clones such as CentOS and Scientific Linux.
Yes, they’ve discontinued support for RHEL 6.X version as of Google Chrome and on other side, latest Firefox and Opera browsers run successfully on the same platforms.
Luckily, there is a script developed by Richard Lloyd, that automatically download and install latest Google Chrome browser by picking libraries from a more recent released distro and put those libraries in (/opt/google/chrome/lib) directory and then you can able to run Google Chrome on RHEL/CentOS 6.x versions.
# wget http://chrome.richardlloyd.org.uk/install_chrome.sh
# chmod u+x install_chrome.sh
# ./install_chrome.sh
Sample Output
Richard Lloyd Google Chrome Script
Google Chrome Installer 7.50 on the x86_64 platform
(C) Richard K. Lloyd 2016 <rklloyd@gmail.com>
*** Creating temporary directory /tmp/chrome_install ...
*** Changing working directory to /tmp/chrome_install ...
*** Generating a list of out-of-date packages (please wait) ...
*** Checking for an update to install_chrome.sh ...
*** Downloading version.dat (please wait) ...
--2017-08-10 02:11:44--  https://chrome.richardlloyd.org.uk/version.dat
Resolving chrome.richardlloyd.org.uk (chrome.richardlloyd.org.uk)... 193.110.246.232
Connecting to chrome.richardlloyd.org.uk (chrome.richardlloyd.org.uk)|193.110.246.232|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5
Saving to: ‘version.dat’
100%[=====================================================================================================================================================>] 5           --.-K/s   in 0s      
2017-08-10 02:11:44 (335 KB/s) - ‘version.dat’ saved [5/5]
*** install_chrome.sh is already the latest version (7.50) - continuing ...
*** Determining latest Google Chrome version number (please wait) ...
*** Downloading chrome_versions.csv (please wait) ...
--2017-08-10 02:11:46--  http://omahaproxy.appspot.com/all?os=linux&channel=stable
Resolving omahaproxy.appspot.com (omahaproxy.appspot.com)... 216.58.220.177, 2404:6800:4009:801::2011
Connecting to omahaproxy.appspot.com (omahaproxy.appspot.com)|216.58.220.177|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 318 [text/plain]
Saving to: ‘chrome_versions.csv’
100%[=====================================================================================================================================================>] 318         --.-K/s   in 0s      
2017-08-10 02:11:46 (39.1 MB/s) - ‘chrome_versions.csv’ saved [318/318]
*** Latest google-chrome-stable version number is 60.0.3112.90 ...
*** Downloading google-chrome-stable_current_x86_64.rpm (please wait) ...
--2017-08-10 02:11:46--  https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
Resolving dl.google.com (dl.google.com)... 216.58.199.142, 2404:6800:4009:806::200e
Connecting to dl.google.com (dl.google.com)|216.58.199.142|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 43781619 (54M) [application/x-rpm]
Saving to: ‘google-chrome-stable_current_x86_64.rpm’
100%[=====================================================================================================================================================>] 5,47,81,619 3.40MB/s   in 14s    
2017-08-10 02:12:00 (3.42 MB/s) - ‘google-chrome-stable_current_x86_64.rpm’ saved [54781619/54781619]
*** Google Chrome 60.0.3112.90 downloaded successfully ...
*** Installing Google Chrome 60.0.3112.90 RPM (please wait) ...
Preparing...                          ################################# [100%]
Updating / installing...
1:google-chrome-stable-60.0.3112.90################################# [100%]
Redirecting to /bin/systemctl start  atd.service
*** Google Chrome 60.0.3112.90 was installed successfully ...
*** /opt/google/chrome tree contains 87 files totalling 181 MB ...
*** /tmp/chrome_install tree contains 1 files totalling 47 MB ...
Google Chrome 60.0.3112.90 was installed successfully.
Please run the browser via the 'google-chrome' command as a non-root user.
To update Google Chrome, run "yum update google-chrome-stable" or
simply re-run this script with "./install_chrome.sh".
To uninstall Google Chrome,
run "yum remove google-chrome-stable " or "./install_chrome.sh -u".

Step 3: Starting Chrome Web Browser

Start browser with non-root user.
# google-chrome &
Welcome screen of Chrome web browser.
Welcome Google Chrome
Welcome Google Chrome
Exploring www.tecmint.com with cool Chrome web browser.
Google Chrome Preview on CentOS 7
Google Chrome Preview on CentOS 7

Friday, October 20, 2017

PATH (variable)

PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.

Contents

History

Multics originated the idea of a search path. The early Unix shell only looked for program names in /bin, but by Version 3 Unix the directory was too large and /usr/bin, and a search path, became part of the operating system.[1]

Unix and Unix-like

On POSIX and Unix-like operating systems, the $PATH variable is specified as a list of one or more directory names separated by colon (:) characters.[2][3]
The /bin, /usr/bin, and /usr/local/bin directories are typically included in most users' $PATH setting (although this varies from implementation to implementation). The superuser also typically has /sbin and /usr/sbin entries for easily executing system administration commands. The current directory (.) is sometimes included by users as well, allowing programs residing in the current working directory to be executed directly. System administrators as a rule do not include it in $PATH in order to prevent the accidental execution of scripts residing in the current directory, such as may be placed there by a malicious tarbomb. In that case, executing such a program requires specifying an absolute (/home/userjoe/bin/script.sh) or relative path (./script.sh) on the command line.
When a command name is specified by the user or an exec call is made from a program, the system searches through $PATH, examining each directory from left to right in the list, looking for a filename that matches the command name. Once found, the program is executed as a child process of the command shell or program that issued the command.

DOS, OS/2, and Windows

On DOS, OS/2, and Windows operating systems, the %PATH% variable is specified as a list of one or more directory names separated by semicolon (;) characters.[4]
The Windows system directory (typically C:\WINDOWS\system32) is typically the first directory in the path, followed by many (but not all) of the directories for installed software packages. Many programs do not appear in the path as they are not designed to be executed from a command window, but rather from a Graphical User Interface. Some programs may add their directory to the front of the PATH variable's content during installation, to speed up the search process and/or override OS commands. In the DOS era, it was customary to add a PATH {program directory};%PATH% or SET PATH={program directory};%PATH% line to AUTOEXEC.BAT.
When a command is entered in a command shell or a system call is made by a program to execute a program, the system first searches the current working directory and then searches the path, examining each directory from left to right, looking for an executable filename that matches the command name given. Executable programs have filename extensions of EXE or COM, and batch scripts have extensions of BAT or CMD. Other executable filename extensions can be registered with the system as well.
Once a matching executable file is found, the system spawns a new process which runs it.
The PATH variable makes it easy to run commonly used programs located in their own folders. If used unwisely, however, the value of the PATH variable can slow down the operating system by searching too many locations, or invalid locations.
Invalid locations can also stop services from running altogether, especially the 'Server' service which is usually a dependency for other services within a Windows Server environment.

Wednesday, October 18, 2017

UNIX / Linux Decompress “.tar.Z”, “.tar.gz”, “.tar.bz2” ,".tgz"

Type man tar for more information, but this command should do the trick:
tar -xvzf community_images.tar.gz
To explain a little further, tar collected all the files into one package, community_images.tar. The gzip program applied compression, hence the gz extension. So the command does a couple things:
  • f: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file.
  • z: tells tar to decompress the archive using gzip
  • x: tar can collect files or extract them. x does the latter.
  • v: makes tar talk a lot. Verbose output shows you all the files being extracted.
 -----------------
Q. I’ve downloaded a file from internet in .tgz format. How do I decompress .tgz file under UNIX or Linux operating system using a shell prompt?

A. This is archive file also known as tar ball. If an archive is compressed with an external tool, the compression program adds its own suffix as usual, resulting in filename endings like “.tar.Z”, “.tar.gz”, and “.tar.bz2” or tgz. To open such file type the following command at Linux shell prompt (GNU tar syntax):
$ tar -zxvf filename.tgz
$ tar -zxvf filename.tar.gz
$ tar -jxvf filename.tar.bz2
 
UNIX decompress tgz / tar.gz file
Type the following command:
$ gzip -dc filename.tgz | tar xf -
$ gzip -dc filename.tar.gz | tar xf -

If file extension ends with .Z, enter:
$ zcat filename.tar.Z | tar xf -

Tuesday, October 17, 2017

jps - Java Virtual Machine Process Status Tool

The Java Virtual Machine has a jps tool wich is a bit like the ps command. jps lists all java Processes of a user. You can find the man page at http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html. I'm using it with the parameters -l (long listing) and -m (arguments) most of the time:
/usr/java/bin/jps -lm
Here are some more examples:
List all java processes: jps
55719 hourglass.jar
51299 jEdit
51610 Main
56026 Jps
Long listing: jps -l
55719 /Users/andreas/.my/pkg/hourglass-0.6.1/lib/hourglass.jar
51299 /Applications/jEdit
56042 sun.tools.jps.Jps
51610 org.netbeans.Main
List arguments: jps -m
55719 hourglass.jar
56051 Jps -m
51299 jEdit 4.2/jedit.jar
51610 Main --userdir /Users/andreas/Library/Application Support/visualvm/1.0.1 --branding visualvm
Java VM parameters: jps -v
56053 Jps -Dapplication.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home -Xms8m
55719 hourglass.jar
51299 jEdit
51610 Main -Djdk.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home

Red Hat / CentOS: Check / List Running Services

How do I list all currently running services in Fedora / RHEL / CentOS Linux server?

There are various ways and tools to find and list all running services under Fedora / RHEL / CentOS Linux systems.

service command – list running services

The syntax is as follows for CentOS/RHEL 6.x and older (pre systemd):
service --status-all
service --status-all | more
service --status-all | grep ntpd
service --status-all | less

Print the status of any service

To print the status of apache (httpd) service:
service httpd status

List all known services (configured via SysV)

chkconfig --list

List service and their open ports

netstat -tulpn

Turn on / off service

ntsysv
chkconfig service off
chkconfig service on
chkconfig httpd off
chkconfig ntpd on

ntsysv is a simple interface for configuring runlevel services which are also configurable through chkconfig. By default, it configures the current runlevel. Just type ntsysv and select service you want to run.

A note about RHEL/CentOS 7.x with systemd

If you are using systemd based distro such as Fedora Linux v22/23/24 or RHEL/CentOS Linux 7.x+. Try the following command to list running services using the systemctl command. It control the systemd system and service manager.

To list systemd services on CentOS/RHEL 7.x+ use

The syntax is:
systemctl
systemctl | more
systemctl | grep httpd
systemctl list-units --type service
systemctl list-units --type mount

To list all services:
systemctl list-unit-files
Sample outputs:
Fig.01: List all units installed on the CentOS /RHEL 7 systemd based system, along with their current states
Fig.01: List all units installed on the CentOS /RHEL 7 systemd based system, along with their current states

To view processes associated with a particular service (cgroup), you can use the systemd-cgtop command. Like the top command, systemd-cgtop lists running processes based on their service:
systemd-cgtop
Sample outputs:
Path                                            Tasks   %CPU   Memory  Input/s Output/s
 
/                                                  85    0.3   240.1M        -        -
/system.slice/NetworkManager.service                2      -        -        -        -
/system.slice/auditd.service                        1      -        -        -        -
/system.slice/crond.service                         1      -        -        -        -
/system.slice/dbus.service                          1      -        -        -        -
/system.slice/lvm2-lvmetad.service                  1      -        -        -        -
/system.slice/polkit.service                        1      -        -        -        -
/system.slice/postfix.service                       3      -        -        -        -
/system.slice/rsyslog.service                       1      -        -        -        -
/system.slice/sshd.service                          1      -        -        -        -
/system.slice/...tty.slice/getty@tty1.service       1      -        -        -        -
/system.slice/systemd-journald.service              1      -        -        -        -
/system.slice/systemd-logind.service                1      -        -        -        -
/system.slice/systemd-udevd.service                 1      -        -        -        -
/system.slice/tuned.service                         1      -        -        -        -
/system.slice/wpa_supplicant.service                1      -        -        -        -
/user.slice/user-0.slice/session-2.scope            1      -        -        -        -
/user.slice/user-1000.slice/session-1.scope         4      -        -        -        -

To list SysV services only on CentOS/RHEL 7.x+ use (does not include native systemd services)

chkconfig --list
Sample outputs:
Fig.02: List Sysv based services on systemd
Fig.02: List Sysv based services on systemd

The ps command

Type the following ps command to display all running process:
# ps -aux | less
OR
# ps aux | less
Where,
  • A : Select all processes
  • u : Select all processes on a terminal, including those of other users
  • x : Select processes without controlling ttys

Task: see every process on the system

# ps -A
# ps -e

Task: See every process except those running as root

# ps -U root -u root -N

Task: See process run by user vivek

# ps -u vivek

Task: top command

The top program provides a dynamic real-time view of a running system. Type the top at command prompt:
# top
Output:
Fig.01: top command: Display Linux Tasks
Fig.01: top command: Display Linux Tasks
To quit press q, for help press h.

Task: display a tree of processes

pstree shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted. If a user name is specified, all process trees rooted at processes owned by that user are shown.
$ pstree
Sample outputs:
Fig.02: pstree - Display a tree of processes
Fig.02: pstree - Display a tree of processes

Task: Print a process tree using ps

# ps -ejH
# ps axjf

Task: Get info about threads

Type the following command:
# ps -eLf
# ps axms

Task: Get security info

Type the following command:
# ps -eo euser,ruser,suser,fuser,f,comm,label
# ps axZ
# ps -eM

Task: Save Process Snapshot to a file

Type the following command:
# top -b -n1 > /tmp/process.log
Or you can email result to yourself:
# top -b -n1 | mail -s 'Process snapshot' you@example.com

Task: Lookup process

Use pgrep command. pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to screen. For example display firefox process id:
$ pgrep firefox
Sample outputs:
3356
Following command will list the process called sshd which is owned by a user called root:
$ pgrep -u root sshd

Say hello to htop and atop

htop is interactive process viewer just like top, but allows to scroll the list vertically and horizontally to see all processes and their full command lines. Tasks related to processes (killing, renicing) can be done without entering their PIDs. To install htop type command:
# apt-get install htop
or
# yum install htop
Now type the htop command at the shell prompt:
# htop
Sample outputs:
Fig.03: htop - Interactive Linux / UNIX process viewer
Fig.03: htop - Interactive Linux / UNIX process viewer (click to enlarge)

atop program

The program atop is an interactive monitor to view the load on a Linux system. It shows the occupation of the most critical hardware resources (from a performance point of view) on system level, i.e. cpu, memory, disk and network. It also shows which processes are responsible for the indicated load with respect to cpu- and memory load on process level; disk- and network load is only shown per process if a kernel patch has been installed. Type the following command to start atop:
# atop
Sample outputs:
Fig.04: atop command in action

How To Use ps, kill, and nice to Manage Processes in Linux

Introduction

A Linux server, like any other computer you may be familiar with, runs applications. To the computer, these are considered "processes".
While Linux will handle the low-level, behind-the-scenes management in a process's life-cycle, you will need a way of interacting with the operating system to manage it from a higher-level.
In this guide, we will discuss some simple aspects of process management. Linux provides an abundant collection of tools for this purpose.
We will explore these ideas on an Ubuntu 12.04 VPS, but any modern Linux distribution will operate in a similar way.

How To View Running Processes in Linux

top

The easiest way to find out what processes are running on your server is to run the top command:
top
top - 15:14:40 up 46 min,  1 user,  load average: 0.00, 0.01, 0.05
Tasks:  56 total,   1 running,  55 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1019600k total,   316576k used,   703024k free,     7652k buffers
Swap:        0k total,        0k used,        0k free,   258976k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND           
    1 root      20   0 24188 2120 1300 S  0.0  0.2   0:00.56 init               
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd           
    3 root      20   0     0    0    0 S  0.0  0.0   0:00.07 ksoftirqd/0        
    6 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0        
    7 root      RT   0     0    0    0 S  0.0  0.0   0:00.03 watchdog/0         
    8 root       0 -20     0    0    0 S  0.0  0.0   0:00.00 cpuset             
    9 root       0 -20     0    0    0 S  0.0  0.0   0:00.00 khelper            
   10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kdevtmpfs          
The top chunk of information give system statistics, such as system load and the total number of tasks.
You can easily see that there is 1 running process, and 55 processes are sleeping (aka idle/not using CPU resources).
The bottom portion has the running processes and their usage statistics.

htop

An improved version of top, called htop, is available in the repositories. Install it with this command:
sudo apt-get install htop
If we run the htop command, we will see that there is a more user-friendly display:
htop
  Mem[|||||||||||           49/995MB]     Load average: 0.00 0.03 0.05 
  CPU[                          0.0%]     Tasks: 21, 3 thr; 1 running
  Swp[                         0/0MB]     Uptime: 00:58:11

  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
 1259 root       20   0 25660  1880  1368 R  0.0  0.2  0:00.06 htop
    1 root       20   0 24188  2120  1300 S  0.0  0.2  0:00.56 /sbin/init
  311 root       20   0 17224   636   440 S  0.0  0.1  0:00.07 upstart-udev-brid
  314 root       20   0 21592  1280   760 S  0.0  0.1  0:00.06 /sbin/udevd --dae
  389 messagebu  20   0 23808   688   444 S  0.0  0.1  0:00.01 dbus-daemon --sys
  407 syslog     20   0  243M  1404  1080 S  0.0  0.1  0:00.02 rsyslogd -c5
  408 syslog     20   0  243M  1404  1080 S  0.0  0.1  0:00.00 rsyslogd -c5
  409 syslog     20   0  243M  1404  1080 S  0.0  0.1  0:00.00 rsyslogd -c5
  406 syslog     20   0  243M  1404  1080 S  0.0  0.1  0:00.04 rsyslogd -c5
  553 root       20   0 15180   400   204 S  0.0  0.0  0:00.01 upstart-socket-br
You can learn more about how to use top and htop here.

How To Use ps to List Processes

Both top and htop provide a nice interface to view running processes similar to a graphical task manager.
However, these tools are not always flexible enough to adequately cover all scenarios. A powerful command called ps is often the answer to these problems.
When called without arguments, the output can be a bit lack-luster:
ps
  PID TTY          TIME CMD
 1017 pts/0    00:00:00 bash
 1262 pts/0    00:00:00 ps
This output shows all of the processes associated with the current user and terminal session. This makes sense because we are only running bash and ps with this terminal currently.
To get a more complete picture of the processes on this system, we can run the following:
ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.2  24188  2120 ?        Ss   14:28   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    14:28   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    14:28   0:00 [ksoftirqd/0]
root         6  0.0  0.0      0     0 ?        S    14:28   0:00 [migration/0]
root         7  0.0  0.0      0     0 ?        S    14:28   0:00 [watchdog/0]
root         8  0.0  0.0      0     0 ?        S<   14:28   0:00 [cpuset]
root         9  0.0  0.0      0     0 ?        S<   14:28   0:00 [khelper]
. . .
These options tell ps to show processes owned by all users (regardless of their terminal association) in a user-friendly format.
To see a tree view, where hierarchal relationships are illustrated, we can run the command with these options:
ps axjf
 PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
    0     2     0     0 ?           -1 S        0   0:00 [kthreadd]
    2     3     0     0 ?           -1 S        0   0:00  \_ [ksoftirqd/0]
    2     6     0     0 ?           -1 S        0   0:00  \_ [migration/0]
    2     7     0     0 ?           -1 S        0   0:00  \_ [watchdog/0]
    2     8     0     0 ?           -1 S<       0   0:00  \_ [cpuset]
    2     9     0     0 ?           -1 S<       0   0:00  \_ [khelper]
    2    10     0     0 ?           -1 S        0   0:00  \_ [kdevtmpfs]
    2    11     0     0 ?           -1 S<       0   0:00  \_ [netns]
. . .
As you can see, the process kthreadd is shown to be a parent of the ksoftirqd/0 process and the others.

A Note About Process IDs

In Linux and Unix-like systems, each process is assigned a process ID, or PID. This is how the operating system identifies and keeps track of processes.
A quick way of getting the PID of a process is with the pgrep command:
pgrep bash
1017
This will simply query the process ID and return it.
The first process spawned at boot, called init, is given the PID of "1".
pgrep init
1
This process is then responsible for spawning every other process on the system. The later processes are given larger PID numbers.
A process's parent is the process that was responsible for spawning it. If a process's parent is killed, then the child processes also die. The parent process's PID is referred to as the PPID.
You can see PID and PPID in the column headers in many process management applications, including top, htop and ps.
Any communication between the user and the operating system about processes involves translating between process names and PIDs at some point during the operation. This is why utilities tell you the PID.

How To Send Processes Signals in Linux

All processes in Linux respond to signals. Signals are an os-level way of telling programs to terminate or modify their behavior.

How To Send Processes Signals by PID

The most common way of passing signals to a program is with the kill command.
As you might expect, the default functionality of this utility is to attempt to kill a process:
kill PID_of_target_process
This sends the TERM signal to the process. The TERM signal tells the process to please terminate. This allows the program to perform clean-up operations and exit smoothly.
If the program is misbehaving and does not exit when given the TERM signal, we can escalate the signal by passing the KILL signal:
kill -KILL PID_of_target_process
This is a special signal that is not sent to the program.
Instead, it is given to the operating system kernel, which shuts down the process. This is used to bypass programs that ignore the signals sent to them.
Each signal has an associated number that can be passed instead of the name. For instance, You can pass "-15" instead of "-TERM", and "-9" instead of "-KILL".

How To Use Signals For Other Purposes

Signals are not only used to shut down programs. They can also be used to perform other actions.
For instance, many daemons will restart when they are given the HUP, or hang-up signal. Apache is one program that operates like this.
sudo kill -HUP pid_of_apache
The above command will cause Apache to reload its configuration file and resume serving content.
You can list all of the signals that are possible to send with kill by typing:
kill -l
1) SIGHUP    2) SIGINT   3) SIGQUIT  4) SIGILL   5) SIGTRAP
 6) SIGABRT  7) SIGBUS   8) SIGFPE   9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
. . .

How To Send Processes Signals by Name

Although the conventional way of sending signals is through the use of PIDs, there are also methods of doing this with regular process names.
The pkill command works in almost exactly the same way as kill, but it operates on a process name instead:
pkill -9 ping
The above command is the equivalent of:
kill -9 `pgrep ping`
If you would like to send a signal to every instance of a certain process, you can use the killall command:
killall firefox
The above command will send the TERM signal to every instance of firefox running on the computer.

How To Adjust Process Priorities

Often, you will want to adjust which processes are given priority in a server environment.
Some processes might be considered mission critical for your situation, while others may be executed whenever there might be leftover resources.
Linux controls priority through a value called niceness.
High priority tasks are considered less nice, because they don't share resources as well. Low priority processes, on the other hand, are nice because they insist on only taking minimal resources.
When we ran top at the beginning of the article, there was a column marked "NI". This is the nice value of the process:
top
 Tasks:  56 total,   1 running,  55 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.3%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1019600k total,   324496k used,   695104k free,     8512k buffers
Swap:        0k total,        0k used,        0k free,   264812k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND           
 1635 root      20   0 17300 1200  920 R  0.3  0.1   0:00.01 top                
    1 root      20   0 24188 2120 1300 S  0.0  0.2   0:00.56 init               
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd           
    3 root      20   0     0    0    0 S  0.0  0.0   0:00.11 ksoftirqd/0
Nice values can range between "-19/-20" (highest priority) and "19/20" (lowest priority) depending on the system.
To run a program with a certain nice value, we can use the nice command:
nice -n 15 command_to_execute
This only works when beginning a new program.
To alter the nice value of a program that is already executing, we use a tool called renice:
renice 0 PID_to_prioritize
Note: While nice operates with a command name by necessity, renice operates by calling the process PID

Conclusion

Process management is a topic that is sometimes difficult for new users to grasp because the tools used are different from their graphical counterparts.
However, the ideas are familiar and intuitive, and with a little practice, will become natural. Because processes are involved in everything you do with a computer system, learning how to effectively control them is an essential skill.
By Justin Ellingwood

Monday, October 16, 2017

Show contents of many files linux

The two standard commands head and tail print a header with the file name if you pass them more than one file argument. To print the whole file, use tail -n +1 (print from the first line onwards, i.e. everything).
Here, it looks like you want to see every file except the single one whose name begins with a dot. Dot files are “hidden” under unix: they don't appear in the default output of ls or in a wildcard match. So matching every non-hidden files is done with just *.
tail -n +1 *
(Strictly speaking, tail -n +1 -- * is needed in case one of the file names begins with a -.)

Setup enviroment variable

Search here for centos jre install all users:
The easiest way to set an environment variable in CentOS is to use export as in
$> export JAVA_HOME=/usr/java/jdk.1.5.0_12

$> export PATH=$PATH:$JAVA_HOME
However, variables set in such a manner are transient i.e. they will disappear the moment you exit the shell. Obviously this is not helpful when setting environment variables that need to persist even when the system reboots. In such cases, you need to set the variables within the system wide profile. In CentOS (I’m using v5.2), the folder /etc/profile.d/ is the recommended place to add customizations to the system profile. For example, when installing the Sun JDK, you might need to set the JAVA_HOME and JRE_HOME environment variables. In this case: Create a new file called java.sh
vim /etc/profile.d/java.sh
Within this file, initialize the necessary environment variables
export JRE_HOME=/usr/java/jdk1.5.0_12/jre
export PATH=$PATH:$JRE_HOME/bin

export JAVA_HOME=/usr/java/jdk1.5.0_12
export JAVA_PATH=$JAVA_HOME

export PATH=$PATH:$JAVA_HOME/bin
Now when you restart your machine, the environment variables within java.sh will be automatically initialized (checkout /etc/profile if you are curious how the files in /etc/profile.d/ are loaded).
PS: If you want to load the environment variables within java.sh without having to restart the machine, you can use the source command as in:
$> source java.sh