Skip to main content

Posts

Showing posts with the label Linux

Static Link or Dynamic linked?

how can you tell whether a program is statically linked? And if it is dynamically linked, how do you know what libraries it needs? The ldd command can answer both questions shiv@ubuntu:~$ ldd /sbin/ldconfig         not a dynamic executable  (ldconfig is not dynmic loadable) shiv@ubuntu:~$ ldd /bin/ln   (ln is dynamic loadable but it needs below listed things to run)         linux-gate.so.1 =>  (0x00918000)         libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00110000)         /lib/ld-linux.so.2 (0x0033f000)  ldconfig ------------ you use the ldconfig command without parameters to rebuild ld.so.cache ldconfig  -p | less to display ld.so.cache how does the dynamic loader know where to look for executables? >>As with many things on Linux, there is a configuration file in /etc. shiv@...

sample program to demonstrate writing daemon program in C and linux

/*  * program to demonstrate writing daemon programs in C and linux  * This Daemon print(adds) time or date every minute, depending on  * user choice t or d to syslog file  */ #include <stdio.h> #include <sys/stat.h> #include <syslog.h> #include <fcntl.h> #include <errno.h> #include <unistd.h> #include <time.h> #include <stdlib.h> /*  * parameters to daemon using argc and argv  */ int main(int c, char *argv[]) {  pid_t pid, sid;  char ch;  time_t t;  char  buf[80];  struct tm *ts; /*  * this daemon expects one argument  * as daemon name is count number 1 and one arg to daemon  * so checking for count <2  */  if(c<2) {     printf("usage: <program name> d | t \n");     return 0;  }  ch = argv[1][0];  printf("The choice is %c\n", ch);  if (!((ch =='d') || (ch =...