Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Tuesday, 23 March 2021

Using a search engine, research operating system timelines

Using a search engine, research operating system timelines
then, based on the OS timelines that you find, answer the following questions: 

Question 1. Why do you think Linux and UNIX share more commands than Windows XP and UNIX?

Solution: Windows operating system is built for a different market peoples.It was mainly fancied over using of the GUI rather than the command line.But whereas Linux built after Unix so they have more number of commands in common.

Question 2. Which line of operating systems has recently become more similar to UNIX?

Solution: The line of operating system which has become more similar to Unix is the Mac OS.

Question 3. Which line of operating systems split into two lines, only to merge again later? 

Solution: The line of operating systems split into two lines, only to merge again later is like MS-Dos in command line and later it is merged into Windows.

Question 4. Why do you think most versions of Linux and Windows use the cd command to change directories? 

Solution: The command is very easy to understand as cd refers to change directory which gives a specific meaning.And also the command is taken from the Unix system

Which of the following files includes device names

Linux
Question 1- Which of the following files includes device names, mount points, filesystem types, permissions and information about whether to mount the device at boot time?

/dev/info
/etc/fstab
/boot/info
/etc/inittab
/etc/mnt
/etc/mount

Solution:  /etc/fstab
/etc/fstab contains information about device names, mount points, filesystem types, permissions and information about whether to mount the device at boot time.

Question 2- What is the process of confirming that an authenticated user has the correct permissions to access one or more network resources?

authorization
authentication
administration
allocation
availability
assignment

Solution: Authorization
Authorization is the process of confirming that an authenticated user has the correct permissions to access one or more network resources.

In Unix operation system

 In Unix operation system , Answer the Questions

Question 1: Write the command to search an user with name Honda , who has already been created ....... ?

Solution:  grep'^Honda' /etc/passwd is the command to search an user with name Honda.

Question 2: Write the command to rename the file F4 to file4 ..?

Solution: mv f4 file4 this command is used to rename. UNIX OS uses the same mv command to move and rename the files.

Question 3: Write the command to search a file having i-node number 3456 ...?

Solution: find /path/to/mountpoint -inum <inode number> this can be used to search a file using i-node number.

Question 4: Write a command to display all file in sorted order based on their names ...?

Solution: ls -la
or
ls -lA
is the command used to display all files in sorted order based on their names.

Saturday, 15 July 2017

Is gettimeofday() guaranteed to be of microsecond resolution?

Question: So I find myself porting a game, that was originally written for the Win32 API, to Linux (well, porting the OS X port of the Win32 port to Linux). I have implemented QueryPerformanceCounter by giving the uSeconds since the process start up:

BOOL QueryPerformanceCounter(LARGE_INTEGER* performanceCount)
{
    gettimeofday(&currentTimeVal, NULL);
    performanceCount->QuadPart = (currentTimeVal.tv_sec - startTimeVal.tv_sec);
    performanceCount->QuadPart *= (1000 * 1000);
    performanceCount->QuadPart += (currentTimeVal.tv_usec - startTimeVal.tv_usec);

    return true;
}

This, coupled with QueryPerformanceFrequency() giving a constant 1000000 as the frequency, works well on my machine, giving me a 64 bit variable that contains uSeconds since the program's start up. So is this portable? I don't want to discover it works differently if the kernel was compiled in a certain way or anything like that. I am fine with it being non-portable to something other than Linux, however.

Solution: Maybe. But you have bigger problems. gettimeofday() can result in incorrect timings if there are processes on your system that change the timer (ie, ntpd). On a "normal" linux, though, I believe the resolution of gettimeofday() is 10us. It can jump forward and backward and time, consequently, based on the processes running on your system. This effectively makes the answer to your question no.
You should look into clock_gettime(CLOCK_MONOTONIC) for timing intervals. It suffers from several less issues due to things like multi-core systems and external clock settings.
Also, look into the clock_getres() function.

Friday, 7 July 2017

What is the fastest way to get the value of π?

Question: I'm looking for the fastest way to obtain the value of π, as a personal challenge. More specifically I'm using ways that don't involve using #defined constants like M_PI, or hard-coding the number in.

Solution:

Bellard's formula, as used by PiHex, the now-completed distributed computing project, is used to calculate the nth digit of π in base 2. It is a faster version (about 43% faster) of the Bailey–Borwein–Plouffe formula.


/**
 * Prints the nth number of pi followed by the next 8 numbers in base 10.
 * This program is based on Bellard's work.
 */

public class Bpp {
 
 final static int NUM = 990; // nth number of pi to print out

 /**
  * Returns the nth digit of pi followed by the next 8 numbers
  * @param n - nth number of pi to return
  * @return returns an integer value containing 8 digits after n
  */
 public int getDecimal(long n) {
  long av, a, vmax, N, num, den, k, kq, kq2, t, v, s, i;
  double sum;

  N = (long) ((n + 20) * Math.log(10) / Math.log(2));

  sum = 0;

  for (a = 3; a <= (2 * N); a = nextPrime(a)) {

   vmax = (long) (Math.log(2 * N) / Math.log(a));
   av = 1;
   for (i = 0; i < vmax; i++)
    av = av * a;

   s = 0;
   num = 1;
   den = 1;
   v = 0;
   kq = 1;
   kq2 = 1;

   for (k = 1; k <= N; k++) {

    t = k;
    if (kq >= a) {
     do {
      t = t / a;
      v--;
     } while ((t % a) == 0);
     kq = 0;
    }
    kq++;
    num = mulMod(num, t, av);

    t = (2 * k - 1);
    if (kq2 >= a) {
     if (kq2 == a) {
      do {
       t = t / a;
       v++;
      } while ((t % a) == 0);
     }
     kq2 -= a;
    }
    den = mulMod(den, t, av);
    kq2 += 2;

    if (v > 0) {
     t = modInverse(den, av);
     t = mulMod(t, num, av);
     t = mulMod(t, k, av);
     for (i = v; i < vmax; i++)
      t = mulMod(t, a, av);
     s += t;
     if (s >= av)
      s -= av;
    }

   }

   t = powMod(10, n - 1, av);
   s = mulMod(s, t, av);
   sum = (sum + (double) s / (double) av) % 1;
  }
  return (int) (sum * 1e9); // 1e9 is 9 decimal places
 }

 private long mulMod(long a, long b, long m) {
  return (long) (a * b) % m;
 }

 private long modInverse(long a, long n) {
  long i = n, v = 0, d = 1;
  while (a > 0) {
   long t = i / a, x = a;
   a = i % x;
   i = x;
   x = d;
   d = v - t * x;
   v = x;
  }
  v %= n;
  if (v < 0)
   v = (v + n) % n;
  return v;
 }

 private long powMod(long a, long b, long m) {
  long tempo;
  if (b == 0)
   tempo = 1;
  else if (b == 1)
   tempo = a;

  else {
   long temp = powMod(a, b / 2, m);
   if (b % 2 == 0)
    tempo = (temp * temp) % m;
   else
    tempo = ((temp * temp) % m) * a % m;
  }
  return tempo;
 }

 private boolean isPrime(long n) {
  if (n == 2 || n == 3)
   return true;
  if (n % 2 == 0 || n % 3 == 0 || n < 2)
   return false;

  long sqrt = (long) Math.sqrt(n) + 1;

  for (long i = 6; i <= sqrt; i += 6) {
   if (n % (i - 1) == 0)
    return false;
   else if (n % (i + 1) == 0)
    return false;
  }
  return true;
 }

 private long nextPrime(long n) {
  if (n < 2)
   return 2;
  if (n == 9223372036854775783L) {
   System.err.println("Next prime number exceeds Long.MAX_VALUE: " + Long.MAX_VALUE);
   return -1;
  }
  for (long i = n + 1;; i++)
   if (isPrime(i))
    return i;
 }

 /**
  * Runs the program
  * @param args
  */
 public static void main(String args[]) {

  long duration = System.currentTimeMillis();

  Bpp bpp = new Bpp();
  System.out.println("Decimal digits of pi at position " + NUM + ": " + bpp.getDecimal(NUM) + "\n");

  duration = System.currentTimeMillis() - duration;
  System.out.println("> " + duration + " ms");
 }

}