1) Diff b/w foreground and background process? How to bring to foreground?
- Unlike with a foreground process, the shell does not have to wait for a background process to end before it can run more processes.
- To run a command as a background process, type the command and add a space and an ampersand to the end of the command. For example: $ command1 &
- Here, While that is running in the background, the shell prompt will return.
- To start a foreground process, enter a command at the prompt, e.g., $ command1
- Here, the next prompt will not appear until command1 finishes running.
- To bring background process to foreground, type $fg to bring the last process back to foreground.
- To get a list of all the background jobs, use $jobs -l and then see our needed process job number and type $fg %<job no>
2) Can we pass input to background process?
- Depends on the type of input
- If you want to type the input, then you will have to put it back in the foreground to type your input, then put it into the background again.
3) Process system calls?
- Exit- terminate the current process
- Fork- create a child process
- Waitpid (OR) Wait4- wait for process termination
- Getpid- get process identification
- Ptrace- allows a parent process to control the execution of a child process
- Pause- suspend process until signal
- Nice- change process priority
- Kill- send signal to process
- Pipe- create an interprocess channel
- Times- get process times
- Brk- change the amount of space allocated for the calling process's data segment
- Setpgid- set process group ID
- Getpgid- get process group ID
- Sys_getsid- get process group ID of session leader
- Getppid- get parent process ID
- Setsid- creates a session and sets the process group ID
- Idle- make process 0 idle
- Personality- set the process execution domain
- Clone- create a child process
- Mlockall- disable paging for calling process
- Munlockall- reenable paging for calling process
- Prctl- operations on a process
- Capget- get process capabilities
- Capset- set process capabilities
- Vfork- create a child process and block parent
4) Command to see list of sizes of files? (similar to df -h for directory)
- Use $ls -s to list file size, or if you prefer $ls -sh for human readable sizes.
- For files use du, and again, $du -h * for human readable sizes. (du = disk usage of files and directories)
-a
|
All files and folder
|
-h
|
Human readable sizes
|
5) Commands to compress- the tar and zip command flavours?
Compressing Files:
Compressing Files:
- gzip {filename} - Eg) gzip mydata.doc (OR) gzip *.jpg
- bzip2 {filename}
- zip {filenameofzip.zip} {filename-to-compress}
- tar -cfzv {filenameoftgz.tgz} {files} (OR)
- tar -cfzv {filenameoftgz2.tbz2} {files}
- gzip -d {.gz file} (OR) gunzip {.gz file}
- bzip2 -d {.bz2-file} (OR) bunzip2 {.bz2-file}
- unzip {.zip file}
- tar -xfzv {.tgz-file} (OR)
- tar -xfzv {.tbz2-file}
- Basic Syntax:
- $find / -name filenametofind
- ○ The first part of the find command is obviously the word find.
- ○ The second part is where to start searching from. Example: ~, /, /dev, etc...
- ○ The next part is an expression which determines what to find. Example: -empty (finds empty files and folders), -executable (find all executable files), -readable (find all readable files), -name (search for all files with the specified name), -atime (find Files Accessed More Than A Certain Number Of Day Ago)
- ○ Finally the last part is the name of the thing to find. Example:
- ■ $find / -name *.mp3 (pattern searching for all files with the extension mp3)
- ■ $find / -readable
- ■ $find / -executable
- ■ $find / -empty
- ■ $find ~ -atime 100 (find all the files within your home folder accessed more than 100 days ago)
- ○ More options on: https://www.lifewire.com/uses-of-linux-command-find-2201100
- ○ To see only the directories in / with name apple, $find / -type d -name apple
- ○ To see only the files in / with name apple, $find / -type f -name apple
- Compare 2 files
- $diff file1 file2
- we can use diff to automatically display for us which lines differ between the two files
- Linux environment variable is an object that contains value. In simple terms it is a pair of data object and their respective values.
- $printenv or $env command can be use to list linux environment variables.
- Various environment variables are:
- ■ $echo $PATH where PATH is an environment variable name and echo is just to print
- ■ $TEMP – location where processes can store temporary files
- ■ $HOME - indicate where a user's home directory is located in the file system.
- ■ $PWD- show present working directory
- ■ $SHELL contains the path to the user's preferred shell
- ■ $TERM contains the type of the running terminal, e.g. xterm-256color.
- ■ $VISUAL contains command to run the full-fledged editor that is used for more demanding tasks, such as editing mail (e.g., vi, vim, emacs etc).
- To add or define our own environment variables:
- ■ $vi ~/.bash_profile (open bash profile)
- ■ PATH= $PATH: $HOME/bin: /home/user1/custom_script (add our directory /home/user1/custom_script in PATH variable)
No comments:
Post a Comment