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

Jan 20, 2009

What is pthread

What is pthread
POSIX Threads is a POSIX standard for threads. The standard defines an API for creating and manipulating threads.
Libraries implementing the POSIX Threads standard are often named Pthreads.

Suppose you have a 100 files in a directory and you need to find out if a keyword occurs in these files. How would you do it in Unix? How would you do

Suppose you have a 100 files in a directory and you need to find out if a keyword occurs in these files. How would you do it in Unix? How would you do it in Windows?
on Unix:
grep (keyword) (file location & pattern)
grep apple *

on windows:
find (file location & pattern) (keyword)
find . -name 'my*'

How would you handle the above situation if say you had 10 million files?
you could run grep as a background process and output the results to a file for later viewing

Jan 17, 2009

How do you programitcally create & terminate a process on linux

How do you programitcally create & terminate a process on linux
Fork(), execu() to create a process, kill() to terminate a process

Jan 16, 2009

How is background and foreground process implemented in unix shell

How is background and foreground process implemented in unix shell
http://linux.about.com/cs/linux101/a/multitasking.htm
How to bring some process in foreground
Fg and bg

what is fork and exec

what is fork and exec
fork() - system call which creates a new process which is identical to the current process. Differences are dependent on the implementation but consider them to be 100% same for now. returns 0 to the newly created process (child process), returns child's pid to the parent (old) process, returns -1 if there was an error and no fork made.
exec() - actually, multiple version of exec (execlp(), execvp(), etc.) replaces the current process with a new process (create an empty main(), compile it then run it with shell's exec, the shell will die). returns nothing (since your process no longer exists as soon as exec() is done)
How it comes together. The basic shell. When calling 'ls', the shell forks, the child then proceeds to do the execlp("ls","ls") call, while the parent simply waits for the child to exit and then print its prompt again. if while 'ls' is running, the parent dies, 'ls' is said to become a 'zombie' (living dead, undead, etc.). The kernel kills the child process (and you thought GTA was violent).
fork is the ONLY way to create a new process in UNIX

unix commands

comm file1 file2 //find the common part of file1 and file2
diff file1 file2 //find the different part of file1 and file2
uniq file1 //find duplicate lines in file1, the duplicate lines should be contiguous
sort file1 //sort the file1 by alphabet

unix find command:

unix find command:
find . -name "rc.conf" -exec chmod o+r '{}' \;
This command will search in the current directory and all sub directories. All files named rc.conf will be processed by the chmod -o+r command. The argument '{}' inserts each found file into the chmod command line. The \; argument indicates the exec command line has ended.