How to change priority of a process with renice
Dec 6th
Unlike “nice” command, the “renice” command expects PID of a process and can be used to alter priority of an already running process. It can take multiple PIDs at a time to alter scheduling priority. However to increase priority of a process, one should have root privileges while reducing the priority can be done by any user. This all applies for the processes owned by self. The following example reduces scheduling priority (sets 10 as priority) of a background process with PID 987.
[neo@techpulp ~]# renice +10 -p 987
To alter scheduling priority of all processes owned by a specific user, the More >
Run a command with low/high priority in Linux
Dec 6th
The “nice” command can be used to alter the priority of a command executed. This commands takes an optional argument with -n option that specific niceness of process going to be created. This option expects an integer ranging from -20 (highest priority) to 19 (lowest priority). This is an optional parameter and its default value is 10. The following example shows how a new software installation using “yum” is set to low priority.
[neo@techpulp ~]# nice yum install Basket
In general a process created in Linux has nice value of 0. So you can use “nice” command to specify lower value to specify More >
How to find where my command is stored in Linux
Dec 6th
The “which” command lets you know exactly which program is run when you type a command at shell prompt. There is an environment variable called PATH which contains list of directories which will be looked up for the executable when a command is attempted to run at command line. The following example shows how the “which” command is used to find the path of “find” executable.
[neo@techpulp ~]# which find /usr/bin/find [neo@techpulp ~]#
How to create PDF file from a man page in Linux
Dec 6th
The ps2pdf command can be used to create PDF in Linux. This command converts PostScript to PDF using ghostscript. You can redirect the output of “man” command to ps2pdf command to geneate PDF out of man page. The following example shows how to create a PDF of ifconfig man page.
[neo@techpulp ~]# man -t ifconfig | ps2pdf - > ifconfig.pdf [neo@techpulp ~]# okular ifconfig.pdf & [neo@techpulp ~]#
How to configure Proxy settings in Firefox Browser
Dec 5th
Open Firefox browser and open preferences window by selecting the menu as shown below. Press “Edit” in the menu bar and then press “Preferences” item in the menu.
This opens up Firefox’s preferences window. In that select “Network” tab under “Advanced” section as shown below.
Then press the “Settings” button to open “Connection Settings” window as shown in the below diagram.
If you have proxy server IP address and port number, just select “Manual proxy configuration” option and enter them in HTTP proxy and port text fields respectively. If you use exactly same proxy for all connections like HTTPS, FTP etc then select More >
How to get exit code of previous command in Bash
Dec 5th
The special variable “$?” returns the exit code of last executed command in Bash shell script. The following example gets the exit code of “grep” command whose exit code will be zero if finds match and 1 otherwise.
#!/bin/bash grep neo users.txt if [ "$?" == "0" ]; then echo User neo detected else echo User neo not found fi
Why my application can’t open more than 1024 or 4096 sockets in Linux
Dec 5th
Typically socket “open” call doesn’t fail unless you have missed out closing the previous connections using “close” system call. Typically Linux/Unix sets a maximum limit for the number of open FDs. That means you can’t keep FDs in open state more than certain number. These settings can’t be changed as a normal user of the system.
These limits can be seen using “ulimit -a” command.
[neo@techpulp ~]# ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 31729 max locked memory (kbytes, -l) 32 max memory More >
Bash shell script to convert string from lower to upper case and vice versa
Dec 5th
The “tr” command can be used to convert a string variable to upper or lower case. The following function in a bash script converts first argument to lower case.
Convert the given argument into an all lower case string.
toLower() {
echo $1 | tr "[:upper:]" "[:lower:]"
}
GENDER=MALE
GENDER=`toLower $GENDER`
echo $GENDER
Convert the given argument into an all upper case string.
toUpper() {
echo $1 | tr "[:lower:]" "[:upper:]"
}
GENDER=male
GENDER=`toUpper $GENDER`
echo $GENDER
Why GNU Make always says `target’ is up to date
Dec 5th
The GNU make expects the rule target to be files by default. That’s why it first checks the presense of a file/directory with the name specified in the rule. For example GNU make attempts to find if a file with name “target1″ with the following Makefile.
target1: prog prog: one.o two.o gcc $^ -o prog
If by chance you have a file or directory with name “target1” in the same directory, GNU Make interprets its last modified date. Because of that some times Make doesn’t compile anything saying target is up to date even if some of the dependencies are changed.
It is More >
GNU Make – How to compile all c files in present directory
Dec 5th
The “shell” built-in function supported by GNU Make can be used to get the list of C source files in a directory. Then a list of corresponding object files can be created by replacing the file extension in the file list. The following example shows how to compile all C source files present in the current directory to generate an executable named “target“. If you are doing copy and paste of the following example, ensure that you place TAB for all commands under each rule. Otherwise GNU Make complains about “missing separator” error.
TARGET=target SRCS=$(shell ls *.c) OBJS=$(SRCS:.c=.o) all: $(TARGET) $(TARGET):$(OBJS) More >


Recent Comments