0% found this document useful (0 votes)
37 views

Lecture Assignment 4 Response

System Programming

Uploaded by

hadiyaharif10
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Lecture Assignment 4 Response

System Programming

Uploaded by

hadiyaharif10
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lecture Assignment Response

1. Is cc, the C compiler, a built-in command of a UNIX-based/like operating system?


No, cc is not a built-in command of the shell. It's a program file that resides somewhere
in the file system. The shell checks if a command is built-in or, if not, searches through
directories in the $PATH environment variable to locate the program file. Making it a
built-in would unnecessarily enlarge the shell as cc is only relevant to C programmers.
2. How can we distinguish between shell built-ins and a program? A built-in command
has no separate program file, while a program requires an executable file in opcode form.
To check if a command is built-in, you can search for its program file using the whereis
command or similar tools.
3. Why not make all library routines and programs part of the shell? Combining all
routines and programs into the shell would create a bloated, difficult-to-manage system.
This would slow down the shell and make debugging and updates more complex,
violating the modular design principle.
4. Is it possible to change the default (login) shell of a user in a UNIX-based/like
operating system? Yes, it is possible. You can change the user’s shell by modifying
the /etc/passwd file, though write access to this file is required.
5. Compare shells with and without a GUI. GUI shells consume more memory but offer
user-friendly interfaces, making them easier for beginners. Non-GUI shells (like sh and
bash) are lightweight, faster, and preferred by experienced users for scripting and
advanced tasks.
6. How can we add a new environment variable? How can we make it persistent? To
add a new environment variable temporarily, use export VAR=value. To make it
persistent, add this line to a shell configuration file (e.g., .bashrc or .profile). Adding a
variable lasts only for the session, while making it persistent ensures it stays available
across sessions.
7. What happens if your program file has the same name as: a) A built-in command?
The built-in command will be executed by default. You can use command or the absolute
path to run your program. b) A program in the $PATH directories?
The first program found in the $PATH with that name will be executed. You can run your
program by specifying its absolute path.
8. Do you prefer using unistd.h system calls or stdlib.h library routines for
environment variables? Using stdlib.h is simpler for most cases (e.g., getenv() and
setenv()), while unistd.h gives more control over the environment but requires dealing
with low-level pointers and memory.
9. Is it possible to access user/shell variables in a program through system calls or
library routines? Yes, you can access environment variables using library routines like
getenv() or by manipulating the environ array in unistd.h.
10. Does sh have the ability to run scripts? Yes, sh can execute scripts by interpreting them
line by line.
11. Can sh run bash scripts? Can bash run sh scripts? sh scripts can run in bash, but
bash-specific features may not work in sh, as bash includes additional features beyond the
POSIX standard

You might also like