You are on page 1of 13

SIMPLE COMMANDS: : Displays the current username. : Displays the current working directory. : Create a new directory.

: Changes the directory. : Print the message.

1.$who am i 2.$pwd 3.$mkdir dirname 4.$cd dirname 5.$echomessage

1.$cat>filename 2.$cat filename


3.$vi filename 4.$bc 5.$script 6.$exit

: To create a new file. : To view the content of already existing file. : To edit the file.
: Provides the basic calculator. : To retrieve previously used commands. : To exit from UNIX

SAVE AND EXIT COMMANDS: Press<ESC> and then :w -> Save the file. :wq -> Save and quit. :q -> Quit. :sh -> Exit from shell programming. DELETE COMMANDS: 1.$rm I filename : To delete the file. 2.$rm r filename : To delete the directory. MOVE COMMANDS: 1.$mv srcfile destfile: To move the source file to destination file. 2.$mv file dirname : To move file into specified directory. 3.$cp srcfile destfile : To copy the source file to destination file.

LISTING COMMANDS: 1.$ls : To list all the files with its attributes. 2.$ls t : To list the file only. 3.$ls d : To list the directories 4.$ls c : To list all the filenames in alphabetical order. 5.$ls a* : To list the files starting with letter a. 6.$ls *a : To list the files ending with letter a. HEAD AND TAIL COMMANDS: 1.$head no filename : Display the number of lines from the file. 2.$tail no filename : Display from the nth line.

AIM: To write a C program for the system calls of UNIX operating system FORK, GETPID, WAIT, EXIT, and EXEC. ALGORITHM: Step 1: Start the program. Step 2: Display the PID of the Parent process. Step 3: Invoke the child process of the same and display its PID. Step 4: If the child process is not invoked, display the error message. Step 5: If PID=0 then display the files and directory in the PWD. Step 6: If PID>0 then the child process is completed, report it. Step 7: Stop the program.

#include<stdio.h> #include<stdlib.h> #include<unistd.h> main() { int pid; printf("\nThe parent ID is %d \n",getpid); pid=fork(); printf("\nThe child ID is %d \n",pid); if(pid<0) { fprintf(stderr,"\nFork failed\n"); exit(-1); } else if(pid==0) { execlp("/bin/ls","ls",NULL); } else } { wait(NULL); printf("\nChild completed\n"); exit(0);

The parent ID is 134513572 The child ID is 0 The child ID is 21272 a.out d1 ha hai io.c axis axis.c aero stat.c typescript

Child completed

AIM: To write a C program for the system calls of UNIX operating system such as STAT, OPENDIR AND READDIR. ALGORITHM: Step 1: Start the program. Step 2: Store the PWD in a DIR variable by the system call function opendir(). Step 3: For every directories within the PWD check status for each directory using stat(). Step 4: If the directory is available display its name and buffer size. Step 5: Stop the program.

#include<stdio.h> #include<sys/types.h> #include<sys/stat.h> #include<dirent.h> main() { struct stat buf; int exists; DIR*d; struct dirent*de; d=opendir("."); if(d==NULL) { fprintf(stderr,"Could not open\".\"\n"); exit(1); } for(de=readdir(d);de!=NULL;de=readdir(d)) { exists=stat(de->d_name,&buf); if(exists<0) { fprintf(stderr,"%s not found \n",de->d_name); } else } } { printf("%s%ld\n",de->d_name,buf.st_size);

I/O SYSTEMS CALLS


AIM: To write a unix program for i/o system calls.

ALGORITHM:
Step 1: Start the program. Step 2: Open the file to be printed in reverse order. Step 3: Move the cursor to EOF. Step 4: Start printing the characters by moving the cursor backwards. Step 5: If the BOF is reached, stop printing. Step 6: Stop the program.

#include<stdio.h> #include<sys/types.h> #include<fcntl.h> main() { int s,fd,n,l=0; char buff[80]; printf("File in reverse order\n"); fd=open("ha",O_RDWR); lseek(fd,-1,2); while(1) { n=read(fd,buff,1); write(1,buff,n); if(lseek(fd,-2,1)==-1) break; } close(fd); }

SIMULATION PROGRAM
AIM: To write a UNIX program for simulation. ALGORITHM:

Step 1: Start the program.


Step 2: Invoke any system commands using the function system(). Step 3: Display the result. Step 4: Stop the program. PROGRAM: #include<stdio.h> main() { system("ls"); system("grep stdio syscall.c"); }

You might also like