Friday, October 21, 2011

Virtual Box Helpfull commands

1. To get the cliipboard working you may have to run following command in your guest operating system ( I run windows XP as host and Ubuntu as guest) and this works for me :)

  $ sudo VBoxClient --clipboard

 2. Will be updating commands as and when I encounter them

Saturday, October 1, 2011

Identifying 32bit/64 bit for different OS

SOLARIS

 If Solaris has been configured for 32 bit, the output of following command will be

command:  $ isainfo -v
output     : 32-bit sparc applications

command: isainfo -b
output     : 32

If Solaris has been configured for 64 bit,

command:  $ isainfo -v
output     : 64-bit sparcv9 applications 32-bit sparc applications

OR
command:  isainfo -b
output      : 64

WINDOWS


LINUX

Thursday, September 8, 2011

Creating a Daemon ...

Most of the time I use daemon() function call to get my things done.
But it is always good to know exactly what are the basic steps that needs to be done to make a process a daemon.

Following is the sample code to create a daemon.
The usual steps are
1. Fork out
2. close parent , following code is to be done in child
3. Set file mode mask
4. open any log files
5. set SID
6. change working directory to something safe..( may be to "/")
7. close standard file descriptors ( stdin, stdout and stderr)
8. have your big loop to perform stuff you want your daemon to perform... :)

-------------------------CODE SAMPLE ---------------------------





#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>

int main(void) {

/* Our process ID and Session ID */
pid_t pid, sid;

/* Fork off the parent process */
pid = fork();
if (pid < 0) {
exit(EXIT_FAILURE);
}
/* If we got a good PID, then
we can exit the parent process. */
if (pid > 0) {
exit(EXIT_SUCCESS);
}

/* Change the file mode mask */
umask(0);

/* Open any logs here */

/* Create a new SID for the child process */
sid = setsid();
if (sid < 0) {
/* Log the failure */
exit(EXIT_FAILURE);
}



/* Change the current working directory */
if ((chdir("/")) < 0) {
/* Log the failure */
exit(EXIT_FAILURE);
}

/* Close out the standard file descriptors */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);

/* Daemon-specific initialization goes here */

/* The Big Loop */
while (1) {
/* Do some task here ... */

sleep(30); /* wait 30 seconds */
}
exit(EXIT_SUCCESS);
}