Unit 3 Flashcards

1
Q

Different exec functions

A
int execl(const char *pathname, const char
*arg0, ... /* (char *)0 */ );
int execv(const char *pathname, char *const
argv[]);
int execle(const char *pathname, const char
*arg0, ..../* (char *)0, char *const envp[] */ );
int execve(const char *pathname, char *const
argv[], char *const envp[]);
int execlp(const char *filename, const char
*arg0, ... /* (char *)0 */ );
int execvp(const char *filename, char *const
argv[]);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

the three major differences in using different forms of exec functions.

A

The calls with v in the name take an array parameter to specify the argv[] array of the new program. The end of the arguments is indicated by an array element containing NULL.
The calls with L in the name take the arguments of the new program as a variable-length argument list to the function itself. The end of the arguments is indicated by a (char *)NULL argument. You should always include the type cast, because NULL is allowed to be an integer constant, and default argument conversions when calling a variadic function won’t convert that to a pointer.
The calls with e in the name take an extra argument (or arguments in the l case) to provide the environment of the new program; otherwise, the program inherits the current process’s environment. This is provided in the same way as the argv array: an array for execve(), separate arguments for execle().
The calls with p in the name search the PATH environment variable to find the program if it doesn’t have a directory in it (i.e. it doesn’t contain a / character). Otherwise, the program name is always treated as a path to the executable.
FreeBSD 5.2 added another variant: execvP (with uppercase P). This is like execvp(), but instead of getting the search path from the PATH +environment variable, it’s an explicit parameter to the function:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Difference between fork and vfork

A

fork() :
Fork() is system call which is used to create new process.
New process created by fork() system call is called child process and the process that invoked fork() system call is called parent process.It uses copy on write. Code of child process is the same as the code of its parent process. Once child process is created, both parent and child processes start their execution from next statement after fork() and both processes get executed simultaneously. Page of one process doesnt affect the page of other process

vfork() :
Vfork() is also system call which is used to create new process. New process created by vfork() system call is called child process and the process that invoked vfork() system call is called parent process. Code of child process is same as code of its parent process. Child process suspends execution of parent process until child process completes its execution as both processes share the same address space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Rules followed to change uid

A

There are rules for who can change the IDs.
1. If the process has superuser privileges, the setuid function sets the real
user ID, effective user ID, and saved set-user-ID to uid.
2. If the process does not have superuser privileges, but uid equals either the
real user ID or the saved set-user-ID, setuid sets only the effective user ID to
uid. The real user ID and the saved set-user-ID are not changed.
3. If neither of these two conditions is true, errno is set to EPERM, and 1 is
returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Note on process accounting

A

When process accounting is enabled, the kernel writes an accounting record each time a process terminates.
• These accounting records are typically a small amount of binary data with
the name of the command,
the amount of CPU time used,
the user ID and group ID,
the starting time, and so on.
• A superuser executes accton with a argument to
enable accounting.
• The accounting records are written to the specified file, which is usually /var/account/acct on FreeBSD
and Mac OS X, /var/account/pacct on Linux, and /var/adm/ pacct on Solaris.
• Accounting is turned off by executing accton without any arguments..

The data required for the accounting record, such as CPU times and number of characters transferred, is kept by the kernel in the process table and initialized whenever a new process is created, as in the child after a fork.
• Each accounting record is written when the process terminates.
• This means that the order of the records in the accounting file corresponds to the termination order of the processes, not the order in which they were started.
• The accounting records correspond to processes, not programs. A new record is initialized by the kernel for the child after a fork, not when a new program is executed. Although exec doesn’t create a
new accounting record, the command name changes, and the AFORK flag is cleared.
• This means that if we have a chain of three programs A execs B, then B execs C, and C exits only a single accounting record is written.
• The command name in the record corresponds to program C, but the CPU times, for example, are the sum for programs A, B, and C.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly