Unix

Published on July 2020 | Categories: Documents | Downloads: 12 | Comments: 0 | Views: 146
of 9
Download PDF   Embed   Report

Comments

Content

 

Unix •

Lists the contents conten ts of the current curren t directory directory..



 ls has many parameters.







You will probably find the following to be the most useful: ls -a Lists all files, including invisible files (files with a leading dot (.)). ls -l Lists all visible files and some attributes.

 

DIRECTORY COMMANDS cd Change directory. Usage: cd <filename>

Eg: cd my-directory cd go to home directory cd .. go up one directory pwd Print working directory on the terminal. ls List the content of a directory. directory. Usage: ls [options] or ls [options] <directory-path> Options: -l list all files in long format. (permissions, users, filesize,date, and time are displayed). -a list all files including those beginning with a “.”  “.”  -F list files distinguishing directories/ executables* symbolic links@ -R recursively list subdirectories encountered. mkdir Create a new directory. Usage: mkdir <directory-path> rmdir Remove a directory if its empty. Usage: rmdir <directory-path>

 

SYMBOLIC LINKS ln Create symbolic links between files or between directories.

Usage: ln [options] <file-to-be-linked> <new-file> ln [options] <directory-to-be-linked> <direct ory-to-be-linked> <my-directory> Options: -s allows linking across file systems and allows the displayof the link‟s name upon ls -l. Eg: ln -s course-file myfile Eg: ln -s course-directory myspace

 

ls -R Recursively lists all files, including those in sub-directories from the current subdirectory to all sub-directories below. below. ls -s Lists all visible files and their file size in blocks. ls -slagF Command for a full directory listing (all attributes). mkdir directory<CR>:This command command is used to create a new directory within the current directory.  pwd<CR>:The pwd command (print working directory) allows you to determine the the  path name of the directory in which you are presently working. rmdir directory<CR>:The rmdir (remove directory) command command is used to delete a directory. You can only delete an empty directory.

 

Most UNIX file system system types have general structure. The central concepts are  superblock, inode, inode, data block, directory directory block, and indir indirection ection block. block. The superblock superblock contains information about the file system as a whole, such as its size (the exact information here depends on the file system). An inode contains all information about a file, except its name. The name is stored in the directory, directory, together with the number of the inode. A directory entry consists of a filename and the number of the inode which represents the file. The inode contains the numbers of several data blocks, which are used to store the data in the file. There is space only for a few data block numbers in the inode, however, however, and if more are needed, more space for pointers to the data blocks is allocated dynamically. dynamically. These dynamically allocated blocks are indirect blocks; the name indicates that in order to find the data block, one has to find its number in the indirect  block first.

 

UNIX SYSTEM CALLS The fork() & getpid() System Call

System call fork() is used to create processes. It takes no arguments and returns a process ID. The purpose of fork() is to create a n ew pr ocess ocess, which which becomes  becomes the child process of proce oces sses wi will l ex ecut cute e the th e n ex t the caller. After a new child process is created,both pr in struction tr uction f oll ow owii ng the fork f ork() () s sys yste tem m call. Therefore, we have to distinguish the

 parent from the child. This can be done by testing th thee returned value value of fork(): • If fork() returns a negative value, the creation of a child process was unsuccessful. • fork() returns a zero to the newly created child process. • fork() returns a positive value, the he process  process ID of the child child pr process, ocess, to the parent. The returned process ID is of type pid_t defined in sys/types.h. • Normally, the process ID is an integer.

 

Moreover,, a process can use function getpid() to retrieve the process ID Moreover assigned to this process. Therefore, after the system call to fork(), a simple test can tell which process is the child. Please note that Unix will make an exact copy of the

 parent„s address space and give it to the child. Therefore, the parent and child processes have separate address spaces. Execution Parent and children execute concurrently Parent waits until children terminate

 

The exec() System Call

The exec functions of Unix-like operating systems are a collection of functions that causes the running process to be completely replaced by the  program passed passed as ar argument gument to the function. As a new process is not creat created, ed, the process ID (PID) does not change across an execute, but the data, heap and stack of the calling process are replaced by those of the new process.

Fork-exec is a commonly used technique in Unix whereby an

executing process spawns a new program. fork() is the name of the system call that the parent process uses to "divide" itself ("fork") into two identical  processes. After calling calling fork(), the created child child process is actually an exact copy of the parent - which would probably be of limited use - so it replaces itself with another process using the system call exec().

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close