0% found this document useful (0 votes)
7 views5 pages

OS Lab VIVA-1

The document provides a comprehensive overview of various Linux commands, system calls, and concepts related to file permissions, directory navigation, process management, and threading. It includes examples of using commands like chmod, cd, grep, and system calls such as fork, exec, and wait. Additionally, it discusses synchronization mechanisms like semaphores and mutexes, along with the producer-consumer problem.

Uploaded by

emorarey16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

OS Lab VIVA-1

The document provides a comprehensive overview of various Linux commands, system calls, and concepts related to file permissions, directory navigation, process management, and threading. It includes examples of using commands like chmod, cd, grep, and system calls such as fork, exec, and wait. Additionally, it discusses synchronization mechanisms like semaphores and mutexes, along with the producer-consumer problem.

Uploaded by

emorarey16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1. How to change file permissions using chmod (symbolic & octal)?

 Symbolic: chmod u+x file.txt → Adds execute permission to the user.

 Octal: chmod 755 file.txt → User gets all permissions (7), group and others get read and
execute (5).

2. How to change directories using cd (rela ve & absolute)?

 Rela ve path: cd foldername → Changes to a folder inside the current directory.

 Absolute path: cd /home/user/folder → Goes directly to the full path from root.

3. Example of using grep to search a pa ern?

 grep "pa ern" file.txt → Finds all lines containing 'pa ern' in file.txt.

 grep -r "main" . → Searches 'main' recursively in all files from the current directory.

4. Internal vs External commands?

 Internal commands are built into the shell (e.g., cd, echo).

 External commands are separate programs stored on disk (e.g., ls, cat).

5. Linux File System Hierarchy?

 / (root) is the top.

 /bin has basic commands,

 /home has user folders,

 /etc has configura on files.

6. File systems in Windows & Linux?

 Windows: NTFS, FAT32.

 Linux: ext3, ext4, XFS, Btrfs.

7. What does ls -l do?

 Lists files in long format showing permissions, owner, size, and modified date.

8. How to delete a directory with files?

 Use rm -r directoryname to delete folder and contents.

 rm -rf force deletes without asking.

9. Redirect input and output in a shell script?

 command > output.txt → Saves output to file.

 command < input.txt → Uses file content as input.

10. Read user input in shell script?

Use read variable.


Example:

bash

read name

echo "Hello $name"

11. Operators in shell scrip ng?

 Arithme c: + - * /

 Comparison: -eq, -ne, -gt

 Logical: && (and), || (or)

12. Variables in shell scrip ng?

 Declared as name=value (no spaces). Use with $name. Example: name="Arjun"; echo $name

13. Common shells in Unix/Linux?

 Bash, Sh, Zsh, Csh, Ksh are common shells.

14. Purpose of open system call?

 Opens a file and returns a file descriptor to perform read/write opera ons.

15. Parameters of read system call?

 read(fd, buffer, count) → Reads count bytes from file descriptor fd into buffer.

16. Purpose of close system call?

 Closes the file descriptor and releases the resources.

17. Parameters of lseek system call?

 lseek(fd, offset, whence) → Changes file offset based on whence (start, current, end).

18. Use of lseek system call?

 To move the file pointer to read/write from a specific posi on.

19. mkdir in C?

 mkdir("foldername", 0777) → Creates a directory with specified permissions.

20. Purpose of rmdir?

 Removes an empty directory.

21. opendir in C?

 DIR *opendir("/path") → Opens a directory for reading.

22. chdir system call?

 Changes the current working directory. Example: chdir("/home/user")


23. Fields in dirent structure?

 d_name: file name, d_type: file type, d_ino: inode number.

24. What is fork()?

 Creates a new child process. Both parent and child con nue execu ng.

25. fork return values?

 0 in child, >0 (child PID) in parent, -1 if fork fails.

26. Purpose of wait()?

 Makes parent wait un l child finishes execu on.

27. getpid and getppid?

 getpid(): returns current process ID, getppid(): returns parent process ID.

28. How many processes with 3 forks?

 2^3 = 8 total processes including parent.

29. Steps to create thread using pthread?

 Include <pthread.h>, define func on, declare pthread_t, call pthread_create().

30. Parameters of pthread_create?

 pthread_create(& d, NULL, func on, arg) → d: thread ID, func on: code to run.

31. pthread_join usage?

 Waits for the thread to finish execu on, helps in synchroniza on.

32. Thread vs Process?

 Threads share memory and are lightweight. Processes have separate memory and more
overhead.

33. When to use mul threading?

 Useful in web servers (handling clients) or games (graphics/input simultaneously).

34. What is a semaphore?

 A semaphore is a variable used for process/thread synchroniza on to control access to


shared resources.

35. sem_init, sem_wait, sem_post?

 sem_init: ini alize semaphore, sem_wait: decrement and block if 0, sem_post: increment
and signal.

36. Mutex vs Semaphore?

 Mutex: Only one owner, used for locking.


 Semaphore: Can have mul ple signals, more flexible.

37. pthread_mutex_init, lock, unlock?

 Init: ini alize mutex, Lock: acquire lock, Unlock: release lock.

38. When to prefer mutex?

 Use mutex when only one thread should access a cri cal sec on, e.g., upda ng a shared
variable.

1. Name 5 system calls

 fork(): Creates a new process.

 exec(): Runs a new program in a process.

 wait(): Parent waits for child to finish.

 open(): Opens a file.

 read(): Reads data from a file.

2. System calls related to directories

 mkdir(): Makes a new directory.

 rmdir(): Removes an empty directory.

 opendir(): Opens a directory to read its files.

 readdir(): Reads a file name in the directory.

 closedir(): Closes the directory.

3. What is a zombie process?

 A process that finished but s ll exists in the system because the parent hasn’t read its status.

4. What is an orphan process?

 A running process whose parent has exited. The system adopts it.

5. Parameters to system calls

 fork(): No parameters.

 exec(): Program name and arguments.


 wait(): Pointer to status variable.

 open(): File name, flags (e.g., read, write).

 read(): File descriptor, buffer, number of bytes.

6. What each system call returns

 fork():

o 0 for child, child’s PID for parent, -1 if error.

 exec(): Returns -1 if failed.

 wait(): Child’s PID or -1 if error.

 open(): File descriptor or -1 if error.

 read(): Number of bytes read or -1 if error.

7. Producer and Consumer (Problem)

 Producer: Adds items to a shared buffer.

 Consumer: Takes items from the buffer.

 Use semaphores to manage:

o Full: Tracks items in buffer.

o Empty: Tracks free space.

o Mutex: Ensures no conflicts.

Revise More VIVA Q&A from workbook Backside

You might also like