Latest Entries »

 

1. Open terminal

2. Log in as root user [ sudo bash ]

3. Enter root passeord

4. Execute : visudo

5. edit this file and append following line at “# Allows people in group wheel to run all commands” section without quote

5.1.   “USERNAME ALL=(ALL) NOPASSWD: ALL”

6. Save and exit the file.

7. Next time you will not get password prompt to log in as root.

Handle SIGHUP in shell script

When any signal is received from os, at that time we need to perform cleanup or to close already open file descriptor and then exit the program/script.

Here I have given one example for SIGHUP using trap .

When process ID will receive kill -1 <PID> ,function1 will be called and while loop will be broken.

function1() {
echo “In function1″
echo “resetting flag”
FLAG=0
}

trap function1 1
FLAG=1
while [ $FLAG -eq 1 ]
do
echo “In while”
sleep 1
done

int count;

void alarm_wakeup(int i)

{
struct itimerval d_wait;
d_wait.it_interval.tv_sec = 0;
d_wait.it_interval.tv_usec = 0;
d_wait.it_value.tv_sec = 1; /* 10 seconds timer */
d_wait.it_value.tv_usec = 0;
if ( ##condition## )
{
setitimer(ITIMER_REAL, &d_wait,0);
count++;

/*put a condition or do some action when counter reaches at particular number or amount of delay has been passed*/
}
else
{
count=0;
}
}

void function_p()
{
struct itimerval d_wait;

d_wait.it_interval.tv_sec = 0;
d_wait.it_interval.tv_usec = 0;
d_wait.it_value.tv_sec = 1; /* 10 seconds timer */
d_wait.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &d_wait,0);

signal(SIGALRM,alarm_wakeup); /* set the Alarm signal capture */

}

Call the function “function_p” :
It will initiate a timer and register an alarm signal for “alarm_wakeup” function, so when timer expired by its time, SIGALRM will be raised and alarm_wakeup will be called.

To handle the debouncing condition:
-On detected state re-initiate the timer and increment counter, if detected state is not there (means state is changed) leave the function without re-initiate the timer.

Sun rays effect in photoshop

1. Open file in Photoshop

Image

2. Duplicate layer

Image

3. Go to Filter-> Blur -> Radial blur

Image

Image

4. Select light effect Screen

Image

5. Duplicate same layer (step 2)

6. Go to Hue/Saturation menu (CTR+U)

Image

 

Image

7. Go to Brightness/Contrast

Image

 

Image

 

Final Image

Image

 

 

Example:

int main(int argc,char *argv[])

{
struct stat st;
printf(“path=%s\n”,argv[1]);
printf(“value=%d\n”,lstat(argv[1],&st));
printf(“—“);
return 0;
}

 The value for file size above 2.0GB will be -1.

Solution: Compile this binary with “-D_FILE_OFFSET_BITS=64″ flag to add large file support.

Follow

Get every new post delivered to your Inbox.

Join 204 other followers