Podcast
Questions and Answers
What command is used to compile a C program named 'teste.c'?
What command is used to compile a C program named 'teste.c'?
- gcc -o teste teste.c (correct)
- cc -execute teste.c
- gcc -run teste.c
- gcc compile teste.c
The option '-Wall' is used to disable warning messages during compilation.
The option '-Wall' is used to disable warning messages during compilation.
False (B)
What is the purpose of the '-O' option in gcc?
What is the purpose of the '-O' option in gcc?
'-O' option is used to optimize the generated code.
The command to execute a compiled program is './______'
The command to execute a compiled program is './______'
What does the command 'gcc -O3 -Wall -c prog.c' perform?
What does the command 'gcc -O3 -Wall -c prog.c' perform?
It is possible to combine the two compilation steps into one command using gcc.
It is possible to combine the two compilation steps into one command using gcc.
What file is generated after the first step of compiling 'prog.c'?
What file is generated after the first step of compiling 'prog.c'?
What does the function wait()
return when called with no child processes?
What does the function wait()
return when called with no child processes?
If a process calls wait()
and all its child processes are still running, it will return immediately.
If a process calls wait()
and all its child processes are still running, it will return immediately.
What action must be taken if execlp()
fails in the given code segment?
What action must be taken if execlp()
fails in the given code segment?
In the code provided, the command list is defined as char *cmd[] = {____};
In the code provided, the command list is defined as char *cmd[] = {____};
Match the following actions with their descriptions:
Match the following actions with their descriptions:
What happens in the parent process after calling fork()
?
What happens in the parent process after calling fork()
?
Raw files are considered the least efficient and slowest method for storing and retrieving data.
Raw files are considered the least efficient and slowest method for storing and retrieving data.
What will the program output after the child process completes?
What will the program output after the child process completes?
What does the function ftell return?
What does the function ftell return?
The fseek function can only move the cursor forward in the file.
The fseek function can only move the cursor forward in the file.
What are the three constants that can be used for the origin parameter in fseek?
What are the three constants that can be used for the origin parameter in fseek?
The function __________ is equivalent to using fseek to move to position 0 in the file.
The function __________ is equivalent to using fseek to move to position 0 in the file.
Which of the following statements about the fseek function is correct?
Which of the following statements about the fseek function is correct?
Match the following fseek parameters with their descriptions:
Match the following fseek parameters with their descriptions:
The displacement value in fseek can only be a positive number.
The displacement value in fseek can only be a positive number.
What would the following line of code do? fseek(fichier, -4, SEEK_CUR)
What would the following line of code do? fseek(fichier, -4, SEEK_CUR)
What function is used to read a single character from a file?
What function is used to read a single character from a file?
The function fgets reads characters until it encounters EOF.
The function fgets reads characters until it encounters EOF.
What does the function ftell do in file handling?
What does the function ftell do in file handling?
To reposition the cursor to the beginning of a file, you can use the function ______.
To reposition the cursor to the beginning of a file, you can use the function ______.
Match the following file handling functions with their descriptions:
Match the following file handling functions with their descriptions:
What is the purpose of the fscanf function?
What is the purpose of the fscanf function?
The function fseek is used to determine the current position in a file.
The function fseek is used to determine the current position in a file.
What does the function fscanf return when it successfully reads data from a file?
What does the function fscanf return when it successfully reads data from a file?
In file handling, the function ______ is used to read a line of text into a string.
In file handling, the function ______ is used to read a line of text into a string.
Which function would you use to move the file cursor back to the beginning of the file?
Which function would you use to move the file cursor back to the beginning of the file?
What is the role of the compiler in the development process?
What is the role of the compiler in the development process?
The gcc is a type of text editor used in Linux.
The gcc is a type of text editor used in Linux.
What file extension is used for programs written in C?
What file extension is used for programs written in C?
The _____ links object files from different modules with the libraries for the application.
The _____ links object files from different modules with the libraries for the application.
Match the following components of system development with their functions:
Match the following components of system development with their functions:
Which one of the following is NOT a component in the system design?
Which one of the following is NOT a component in the system design?
The shell is an integral part of the system architecture in UNIX.
The shell is an integral part of the system architecture in UNIX.
Name one commonly used text editor in UNIX for writing C programs.
Name one commonly used text editor in UNIX for writing C programs.
What does fork() do in a process management context?
What does fork() do in a process management context?
If fork() returns -1, it indicates that a new process has been successfully created.
If fork() returns -1, it indicates that a new process has been successfully created.
What error code does a process receive when it needs to retry its duplicate request?
What error code does a process receive when it needs to retry its duplicate request?
In the fork() example, the child process prints ‘CHILD %d’ while the parent process prints ‘______ %d’.
In the fork() example, the child process prints ‘CHILD %d’ while the parent process prints ‘______ %d’.
Match the programming construct with its description:
Match the programming construct with its description:
In what scenario would a process enter the do-while loop when calling fork()?
In what scenario would a process enter the do-while loop when calling fork()?
A parent process must wait for the child process to finish before it can continue executing.
A parent process must wait for the child process to finish before it can continue executing.
What is printed by the child process if the fork() returns 0?
What is printed by the child process if the fork() returns 0?
In the second fork() example, the variable 'pid' is of type ______.
In the second fork() example, the variable 'pid' is of type ______.
Which of the following is an incorrect way to use a for loop in the provided code?
Which of the following is an incorrect way to use a for loop in the provided code?
Flashcards
Unix Kernel
Unix Kernel
The core of any Unix system, responsible for managing resources and interacting with hardware.
Shell
Shell
A command line interpreter used to interact with the Unix kernel, allowing users to execute commands and manage the system.
Libraries
Libraries
A collection of pre-written code modules that can be used in programs to perform common tasks, providing reusable functionality.
Utilities
Utilities
Signup and view all the flashcards
Unix System Design
Unix System Design
Signup and view all the flashcards
Compilation
Compilation
Signup and view all the flashcards
Linking
Linking
Signup and view all the flashcards
GCC (GNU Compiler Collection)
GCC (GNU Compiler Collection)
Signup and view all the flashcards
gcc
gcc
Signup and view all the flashcards
Code Optimization
Code Optimization
Signup and view all the flashcards
Warnings (or -Wall flag during compilation)
Warnings (or -Wall flag during compilation)
Signup and view all the flashcards
Object file
Object file
Signup and view all the flashcards
fgetc()
fgetc()
Signup and view all the flashcards
fgets()
fgets()
Signup and view all the flashcards
fscanf()
fscanf()
Signup and view all the flashcards
ftell()
ftell()
Signup and view all the flashcards
fseek()
fseek()
Signup and view all the flashcards
rewind()
rewind()
Signup and view all the flashcards
EOF
EOF
Signup and view all the flashcards
fork()
fork()
Signup and view all the flashcards
EAGAIN
EAGAIN
Signup and view all the flashcards
fork() loop with EAGAIN check
fork() loop with EAGAIN check
Signup and view all the flashcards
PID
PID
Signup and view all the flashcards
PPID
PPID
Signup and view all the flashcards
getpid()
getpid()
Signup and view all the flashcards
getppid()
getppid()
Signup and view all the flashcards
wait()
wait()
Signup and view all the flashcards
Process request retries
Process request retries
Signup and view all the flashcards
Fork() Example (prog.c)
Fork() Example (prog.c)
Signup and view all the flashcards
wait() Function
wait() Function
Signup and view all the flashcards
Forking a Process
Forking a Process
Signup and view all the flashcards
execlp() Function
execlp() Function
Signup and view all the flashcards
Raw Files
Raw Files
Signup and view all the flashcards
Formatted File
Formatted File
Signup and view all the flashcards
Parent Process
Parent Process
Signup and view all the flashcards
Child Process
Child Process
Signup and view all the flashcards
What is the ftell()
function?
What is the ftell()
function?
Signup and view all the flashcards
Explain the purpose of the fseek()
function.
Explain the purpose of the fseek()
function.
Signup and view all the flashcards
What are the different origins of the file pointer in the fseek()
function?
What are the different origins of the file pointer in the fseek()
function?
Signup and view all the flashcards
What is the purpose of the SEEK_SET
constant in the fseek()
function?
What is the purpose of the SEEK_SET
constant in the fseek()
function?
Signup and view all the flashcards
What is the purpose of the SEEK_CUR
constant in the fseek()
function?
What is the purpose of the SEEK_CUR
constant in the fseek()
function?
Signup and view all the flashcards
What is the purpose of the SEEK_END
constant in the fseek()
function?
What is the purpose of the SEEK_END
constant in the fseek()
function?
Signup and view all the flashcards
Explain the purpose of the rewind()
function.
Explain the purpose of the rewind()
function.
Signup and view all the flashcards
How does rewind()
relate to fseek()
?
How does rewind()
relate to fseek()
?
Signup and view all the flashcards
Study Notes
Introduction
- This document contains notes on the presentation of programming systems, specifically focusing on processes.
Processes
- A process is the memory image of a program currently running. It has a life cycle. It begins, runs, and then ends.
- A program launched twice creates two distinct processes.
- Every process is identified in memory by a unique number assigned by the operating system called the PID (Process ID).
Process Tree in a Unix System
- The init process is the parent of all other processes in a Unix system.
- init assigns the machine name, initializes the date and time, and ensures the system has been properly shut down.
- It starts the "getty" process which displays "login" prompt on a terminal and waits for input.
- It also launches the "inetd" process for network monitoring.
- Processes ending in "d" are called "daemon" processes that are server processes which work in continuous loops to provide consistent service to clients.
Process States
- Initial: newly created, in transition.
- Active: the process is executing.
- Waiting: the process is paused and relinquishes the CPU to another process.
- Terminating: the process has finished execution.
Process Concepts
- A processor executes one task at a time.
- The process has various states, such as "Ready," "Running," "Blocked," and "Terminated." These states depict the behavior of the process.
- Transitions happen between states on event occurrence. For instance, a process can transition to 'ready' from 'blocked' or 'terminated' on completion.
Process Creation
- User processes are launched by a command interpreter (shell). They can also create further processes.
- Processes need to interact among each other.
- The creator process is termed a "Parent" process.
- Processes created are referred to as "Children" processes.
Process Termination
- Process termination can be done in 3 ways:
- Normal Termination: Finishing its operations
- Permitted Termination: By the parent process executing a suitable command
- Abnormal Termination: By the system, such as exceeding execution time or insufficient memory.
Implementation
- The operating system maintains a process table, or table of processes, to track individual processes.
- Each entry contains information about the process, including its status, instruction address, stack pointer, open files, and the allocated memory.
Process Structure
- An operating system process comprises various elements such as PID (Process ID), UID (User ID), GID (Group ID), open files, maximum file size, and priority.
- The Terminal is the terminal from which a command was executed.
Priorities
- Under Linux, processes have a priority of -20 to 19 to control execution order.
- Higher values indicate lower priority.
- The nice command is used to adjust process priority
Example: Structure of a Unix Process
- Processes have unique IDs.
- Processes have sets of open files and a current directory.
- Processes have a certain priority, and execution time.
The ps command
- Shows information about running processes.
- Provides a list of processes linked to a specific terminal, along with CPU utilisation data.
- Useful for viewing processes that aren't linked with terminals.
The kill command
- Sends a signal to a process to perform an action.
- Accepts a signal number.
Signals
- A signal in an operating system is an asynchronous event that can interrupt the running of a program.
- Signals can be generated by hardware events (e.g., a signal to inform a process that an interrupt has occurred), the operating system itself, another process, or an error condition within the process.
- Example Signals: SIGINT, SIGQUIT, SIGKILL, etc.
Job Management
- A job is a collection of one or more commands.
- Commands, including programs, can be made into a job.
- Launch jobs in the background via the '&' character.
- The "jobs" command displays all running jobs.
- Use the 'bg' command to resume the execution of a stopped job.
- Use the 'fg' command to bring a job into the foreground.
Linux Management of Services
- The "service" command manipulates machine services.
- Shows status of all running services.
- Useful for managing processes.
Concepts and Tools.
- General information about Linux development.
- Information for developers on interaction between application and the machine.
- Information about system calls.
Development in Linux
- There are three basic steps in Linux development:
- Editing the source code.
- Compiling the source code into an executable file.
- Linking the object files with the required libraries into a single executable file.
Compiling and Linking
- The compiler/linker (gcc) converts source code into machine language.
- Different options are used during compilation, like ‘-g’ for debugging and ‘-Wall’ to display warnings.
Execution
- An example of how to run C code.
- How to compile, execute programs in Linux.
Example
- Illustrative examples for various program execution scenarios.
Compilation in C
- Explains the compilation process in C programs using
gcc
.
The Makefile
- Managing multiple source files and dependencies within a C project.
- Using a makefile to automate compilation for large projects.
- Ways to write the different rules to automate compilation.
- Ways to define rules to automate compilation.
- Ways to define variables within a makefile for reuse.
- A guide on how to write, read and correctly interpret a makefile.
Parameters to "main()"
- Explanation of parameters in the
main()
function in a C program, includingargc
,argv
, andenvp
. - Explains what each parameter represents and how they are used within the program.
- Gives some example implementations in order to better understand their usage.
The PATH Variable
- The value of PATH is a set of paths.
- The executables are searched at all the paths defined within the PATH value.
Access to Environment
- How to access environment variables in code.
- Example usage and retrieval of values.
System Calls C
- Methods for creating and manipulating processes in C.
- Explanation of the system calls and their use in controlling process behavior.
- Description of the 'fork' system call.
The fork
System Call
- Usage: Creation of child processes, and how processes can communicate with each other after using fork().
Process Presentation
- Explains how processes are presented.
- Clarifies the parent-child relationship between two processes, and illustrates how the system deals with the parent process after the creation of a child process.
The wait
System Call
- How to wait for a child process's status after the fork system call is used.
- This call is used to ensure the parent process stops till the child process ends, therefore allowing processes to complete in sequence.
Displaying the Date with the Child Process
- Demonstrates an example of using the
fork
andexecv
system calls to run a command, and capture its output to display within the current application.
Implementing Files
- Describes the various methods for interacting with files.
- Explains how raw file manipulation can differ from the standard input and output operations.
File Descriptors
- Discusses the concept of file descriptors for identifying files in a C program
- Explains the importance of understanding file descriptors in performing file operations.
stat
Structure
- How to access file details using
stat
. - Describes the contents of the
struct stat
to indicate file information like permissions, creation, modification, and access times.
File Writing
- Explanation of writing operations on files in C using the
write
system call.
File Reading
- Explanation of reading operations on files in C using the
read
system call.
File Management
- Various methods for managing and manipulating files in C, including creating, writing, reading, closing, and renaming files.
File Buffering
- Explains file buffering and its relationship with file I/O operations.
File Operations
- A summary of file operations and the necessary headers.
Standard POSIX
- Summary of the POSIX standard and its relevance to file operations.
Named Pipes
- Explanation of named pipes for inter-process communication.
- Showing how named pipes can persist across process terminations.
Signal Handling
- Introduction to signals and how they can be handled in C programs to make applications more robust.
- Illustrates how signal handling can be managed in processes to handle errors, or to perform some task when an error is encountered.
Signals : CTRL-C & CTRL-Z
- Illustrates how the
CTRL+C
andCTRL+Z
commands can be used to interrupt a program.
Signal Handling
- Explains different ways to handle signals.
- Explanation of how to handle signals including the use of
signal()
,pause()
, andalarm()
. - Explains the structure, role, handling of signals.
- Includes code examples, to help to understand the different signal handling.
Signal Interface
- Explains the interface for managing signals in C programs.
Signal Values in Unix
- Explains the different signal values in Unix-like systems (Linux).
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.