Skip to main content

Posts

Showing posts from June 12, 2014

Plenty of Programs of UNIX

Hey Guys Check Out The Following Link of Plenty of Programs of UNIX Download & Enjoy The Stuff. Follow The Given Link Below  Download UNIX Programs Bunch Here

Write programs to demonstrate communication between two processes. First process while send content of file to second process. Second process displays content by changing case.

#include #include #include main(int agrc,char *argv[]) {     int fd[2],pid,n,f,ch;     char buffer[2048],*cha;     if(pipe(fd)==-1)     {         printf(" problem to create the pipe \n ");         exit(0);     }     else     {         pid=fork();         if(pid!=0)         {             close(fd[0]);             f = open("hardik",O_RDONLY);             while((n = read(f,buffer,2048)) > 0)             {                 write(fd[1],buffer,n);             }             close(fd[1]);         }         else         {             close(fd[1]);             ch = 0;             while((n=read(fd[0],cha,1)) > 0)             {                 if(*cha >= 'a' && *cha <= 'z')                 {                     printf("%c",*cha - 32);                 }                 else if(*cha >= 'A' && *cha <= 'Z')                 {                     printf("%c",

Write a program to create a pipe and share between parent and child process. Parent writes content to pipe from the file and child reads the content and display number of characters.

#include #include #include #include main(int agrc,char *argv[]) {     int fd[2],pid,n,f,ch;     char buffer[2048];     if(pipe(fd)==-1)     {         printf(" problem to create the pipe \n ");         exit(0);     }     else     {         pid=fork();         if(pid!=0)         {             close(fd[0]);             f = open("hardik",O_RDONLY);             while((n = read(f,buffer,2048)) > 0)             {                 write(fd[1],buffer,n);             }             close(fd[1]);         }         else         {             close(fd[1]);             ch = 0;             while((n=read(fd[0],buffer,2048)) > 0)             {                 ch = ch + n;             }             printf("Number of Charecter:-%d",ch-1);             close(fd[0]);         }     } }

Write a program to execute ls command in child process. Parent process must wait for child termination.

#include #include #include main() {     int pid,w,Status;     printf("PRENT PROCESS PORTION  \n");     pid=fork();     if(pid==0)     {         printf("child process part \n ");         execl("/bin/ls","ls",0);     }     sleep(3);     w = wait(&Status);     printf("parent process after child execution \n "); }

Write a program to create a child process in which child process displays number of line sent by parent process.

#include #include #include #include #include main(int agrc,char *argv[]) {     int fd[2],pid,line=0,n;     char buffer[2048]="Milind Audichya\Dhruv Naik\Uzer Pathan\n",buffer2[1];     if(pipe(fd)==-1)     {         printf(" problem to create the pipe \n ");         exit(0);     }     else     {         pid=fork();         if(pid!=0)         {             printf("Perent Send Data To Chlid Data is:- %s ",buffer);             close(fd[0]);             write(fd[1],buffer,strlen(buffer));             close(fd[1]);         }         else         {             close(fd[1]);             printf("Chlid Process Read The Content send by the Perent.");             while((n=read(fd[0],buffer2,1)) == 1)             {                 if(buffer2[0] == '\n')                 {                     line++;                 }             }             printf("Number of line send by Perent:-%d",line);          

Write a program to create three child process. The parent process send the signal to terminate all these child processes.

#include #include main() {     int pid[3],status,i;     for(i=0;i<3 i="" p="">    {     pid[i]=fork();     printf("\n new created child process value is :%d",pid[i]);     }     for(i=0;i<3 i="" p="">    {         if(pid[i])         {             printf("for terminate the process  \n");             kill(pid[i],9);             printf("termination of the child process :%d \n ",pid[i]);         }     } } }

Write a program to create a child process. Parent process will display message child process terminated on termination of child process. (Hint: catch SIGCHLD signal in parent)

# include # include # include # include # include void handler(int sig) {       printf("Iam in handler ...%d\n",sig); }   main() {     int status;     pid_t pid;     signal(SIGCHLD,handler);     pid = fork();     printf("Child Process id is : %d\n", pid);     if( pid == 0 )         {         printf("child process id is  %d\n",getpid());         exit(0);     }     sleep(3);     pid = wait(&status);     printf("process terminated is %d\n",pid); }

Write a program to create a child process. Parent process will display three messages. First message will displayed before creation of child process. Second message will displayed only if child process is alive. Last message will displayed after completion of child process.

#include #include main(int argc,char *argv[]) { int pid,w,status; printf("parent process before the child process created \n"); pid=fork(); if(pid==0) { printf("Parent process during creating the child process \n"); } sleep(3); w=wait(&status); printf(" parent process after the executing child process \n"); } /* sai@sai-VirtualBox:~/Desktop$ cc -o p4 p4.c p4.c: In function main: p4.c:8:2: warning: incompatible implicit declaration of built-in function printf [enabled by default] sai@sai-VirtualBox:~/Desktop$ ./p4 parent process before the child process created Parent process during creating the child process parent process after the executing child process parent process after the executing child process */

Write a command line program to accept file name followed by a number say N1. Display line N1 in reverse order of its characters.

#include #include #include #include #include char buffer[2048]; void readLine(int fd, int LineNo); main(int argc,char *argv[]) {    int fd,LineNo;      if(argc != 3)    {        printf("Enter The Two Argument First File Name And Other Line No..!!");        exit(0);          }              fd = open(argv[1],O_RDONLY);    if(fd == -1)    {        printf("File Is Not Open");        exit(0);    }    LineNo = atoi(argv[2]);    readLine(fd,LineNo); } void readLine(int fd, int LineNo) {    int count,i,line=0,t=0,j;    char Line[100],OneL[100],ch[]= { ' ', ' '};    while((count = read(fd,buffer,sizeof(buffer))) > 0)    {        for (i=0;i < count;i++)        {            if(buffer[i] == '\n')            {                Line[t++] = '\0';                t=0;                strcpy(OneL,Line);                strcpy(Line,ch);                              line++;                            

Write a command line program to accept number say N1. Display all files from the current directory, whose size is greater than N1.

#include #include #include #include #include #include char path[50]; int main(int argc, char* argv[]) {     int size;     // to get the Current Directory Path Used This System Call..!!       getcwd(path,50);     printf("Current Directory Path Is:%s\n",path);     DIR *mydir;     struct dirent *myfile;     struct stat mystat;     mydir = opendir(path);     while((myfile = readdir(mydir)) != NULL)     {         stat(myfile->d_name, &mystat);       size = atoi(argv[1]);     if(mystat.st_size > size)     {         printf("%d",mystat.st_size);         printf(" %s\n", myfile->d_name);       }             }     closedir(mydir); }

Write a program which take a file name as a command line argument. Count the number of characters, number of words, number of line, number of vowels and display them on screen.

#include #include #include char buffer[2048]; int main(int argc,char *argv[]) {     int fdold;     int count;     int i,word,space,vovals,line,ch;     word = 0;     space = 0;     vovals = 0;     line = 0 ;     ch=0; if(argc  == 2) {     fdold = open(argv[1],O_RDONLY);       if(fdold == -1)     {         printf("cannot open file ");     }     else     {         while((count = read(fdold,buffer,sizeof(buffer))) > 0)         {             for (i=0;i             {                 if(buffer[i] == ' ' || buffer[i] == '.')                 {                     word++;                 }                 if(buffer[i] == ' ')                 {                     space++;                 }                 if(buffer[i] == 'a' || buffer[i] == 'e' || buffer[i] == 'i' || buffer[i] == 'o' || buffer[i] == 'u' ||                     buffer[i] == 'A' || buffer[i] == 'E

Use Your SMILE TO CHANGE THE WORLD

Use Your SMILE "TO CHANGE THE WORLD" but "DON'T LET THIS WORLD CHANGE YOUR SMILE"