OS Lab VIVA-1
OS Lab VIVA-1
Octal: chmod 755 file.txt → User gets all permissions (7), group and others get read and
execute (5).
Absolute path: cd /home/user/folder → Goes directly to the full path from root.
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.
Internal commands are built into the shell (e.g., cd, echo).
External commands are separate programs stored on disk (e.g., ls, cat).
Lists files in long format showing permissions, owner, size, and modified date.
bash
read name
Arithme c: + - * /
Declared as name=value (no spaces). Use with $name. Example: name="Arjun"; echo $name
Opens a file and returns a file descriptor to perform read/write opera ons.
read(fd, buffer, count) → Reads count bytes from file descriptor fd into buffer.
lseek(fd, offset, whence) → Changes file offset based on whence (start, current, end).
19. mkdir in C?
21. opendir in C?
Creates a new child process. Both parent and child con nue execu ng.
getpid(): returns current process ID, getppid(): returns parent process ID.
pthread_create(& d, NULL, func on, arg) → d: thread ID, func on: code to run.
Waits for the thread to finish execu on, helps in synchroniza on.
Threads share memory and are lightweight. Processes have separate memory and more
overhead.
sem_init: ini alize semaphore, sem_wait: decrement and block if 0, sem_post: increment
and signal.
Init: ini alize mutex, Lock: acquire lock, Unlock: release lock.
Use mutex when only one thread should access a cri cal sec on, e.g., upda ng a shared
variable.
A process that finished but s ll exists in the system because the parent hasn’t read its status.
A running process whose parent has exited. The system adopts it.
fork(): No parameters.
fork():