UNIX and C Processes Flashcards

(64 cards)

1
Q

What is POSIX?

A

Portable Operating System Interface; IEEE Computer Society standard from 1988 that enables developers to write portable applications across UNIX variants and other operating systems.

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

What does POSIX define?

A

POSIX defines an application programming interface (API), command line shells, utility interfaces, and describes fundamental services needed for applications.

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

What is the Single UNIX Specification?

A

A standard created by The Open Group in 1995 to ensure compatibility across UNIX platforms; technically conforms to POSIX.

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

Which Linux distributions are officially certified UNIX systems?

A

Only Inspur K-UX and EulerOS are officially certified UNIX systems.

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

What are examples of fully certified UNIX systems?

A

Oracle Solaris, HP-UX, IBM AIX, Apple MacOS X (version 10.5 onwards), Inspur K-UX, and Huawei EulerOS.

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

What are the two fundamental elements of UNIX?

A

Everything in UNIX is either a file or a process.

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

What is a PID?

A

Process IDentifier; a unique identifier assigned to every process in a UNIX system.

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

What are the parent-child relationships in UNIX processes?

A

Every process has exactly one parent (except the system swapper with PID 0), and can have zero or more children.

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

What is the system swapper/init process?

A

The system swapper has PID 0 and is the ancestor of every process; init or systemd (PID 1 on Linux) is part of the Linux kernel.

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

How is a child process created in UNIX?

A

A child process is created (“spawned”) when the system fork command is called.

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

What does the ps command do?

A

Shows a snapshot of processes.

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

What does the top command do?

A

Shows a real-time list of processes.

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

What does & do when placed after a command?

A

Runs the process in the background.

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

What does the jobs command show?

A

Lists the background child processes of the current process.

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

What does the bg command do?

A

Puts a paused job into the background.

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

What does the fg command do?

A

Brings a background job into the foreground.

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

What does the kill command do?

A

Terminates a process.

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

What does the nohup command do?

A

Keeps a child process running even when the parent process finishes.

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

What does the nice command do?

A

Lowers the priority of a child process as you spawn it.

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

What does the renice command do?

A

Lowers the priority of a current running process.

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

How do you show all processes from the same terminal?

A

ps

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

How do you show full details of your processes?

A

ps -f

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

How do you show all processes whose command line includes “python” (ignoring case)?

A

ps -ef | grep -i python

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

How do you show the parent/child hierarchy of all processes?

A

ps -efH | less

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What's the difference between foreground and background processes?
Foreground: shell waits until process finishes. Background: user can continue interacting with the shell while process runs.
26
How do you run a program in the background?
Add & after the command (e.g., tempsleep &)
27
How do you put a foreground process into the background?
Press CTRL-Z to stop it, then use bg %[job number]
28
What happens to background processes when the parent process finishes?
They are killed unless protected with nohup
29
How do you kill a process using its job number?
kill %[job number]
30
How do you kill a process using its PID?
kill [PID]
31
How do you start a process with lower priority?
nice [command]
32
How do you change the priority of a running process?
renice -n [value] -p [PID]
33
How do you enable a child process to continue running after logout?
nohup [command] &
34
What does the fork() function do in C?
Creates a duplicate process (child) of the calling process (parent).
35
What value does fork() return in the parent process?
The PID of the child process.
36
What value does fork() return in the child process?
0
37
What value does fork() return if it fails?
A negative value
38
What elements do parent and child processes share after fork()?
They share variable values from before the fork and any open file descriptors (e.g., stdout)
39
How does a parent wait for a specific child process to finish?
Using waitpid(pid, &status, 0)
40
How does a parent wait for any child process to finish?
Using waitpid(0, &status, 0)
41
What flag makes waitpid() return immediately if no child has exited?
WNOHANG
42
What header file is required for waitpid() function?
#include
43
What do the exec family of functions do?
Replace the current process with a new program.
44
Does code after a successful exec call ever execute?
No, the process is completely replaced. Code after exec only executes if exec fails
45
What is the prototype of the execvp function?
int execvp(const char *file, char *const argv[]);
46
What is a pipe in Linux/C?
A unidirectional flow of data between two processes.
47
When must a pipe be opened relative to the fork?
Before the fork, so that parent and child share it.
48
How is a pipe created in C?
Using the pipe(fd) function, where fd is an array of two file descriptors.
49
What are the file descriptors in a pipe used for?
fd[0] is the reading end (front) of the pipe, and fd[1] is the writing end (rear) of the pipe.
50
Are pipes buffered?
No, pipes are unbuffered.
51
What is a signal in UNIX/Linux?
A software interrupt delivered to a process to notify it of an event.
52
What does the kill command actually do?
It sends a signal to a process (by default, SIGTERM).
53
What signal does CTRL-C send to a process?
SIGINT (interrupt signal)
54
Which signal cannot be caught by a program?
SIGKILL (causes immediate termination by the kernel)
55
How can a program set up a handler for a signal?
Using the signal() function to register a handler function for a specific signal
56
How do you define a signal handler in C?
Create a function like void sig_handler(int signo) and register it with signal(SIGNAL, sig_handler)
57
How do you send a USR1 signal to a process?
kill -USR1 [PID] or kill -USR1 %[job number]
58
What signals can programmers use for their own purposes?
SIGUSR1 and SIGUSR2
59
Can a program catch a SIGSEGV signal?
Yes, though handling segmentation faults properly is complex.
60
What are three ways processes can communicate?
Signals, files, and pipes.
61
Which communication method requires knowing the PID of the target process?
Signals
62
Which communication method allows data transfer but requires processes to be parent/child or siblings?
Pipes
63
Which communication method allows data transfer between any processes?
Files (though file locking must be considered)
64
Which communication method is asynchronous (receiving process doesn't need to keep checking)?
Signals