linux-sysprog · beginner · ~15 min

Same namespace?

Compare namespace identifiers.

Challenge

Each namespace is identified by the inode number of its /proc/<pid>/ns/* file; two processes share a namespace exactly when those ids match.

Task

Implement int same_namespace(unsigned long a, unsigned long b) that returns 1 if the two namespace ids are equal, else 0.

Input

  • a, b: namespace inode ids (unsigned).

Output

1 if a == b, else 0.

Example

same_namespace(4026531835, 4026531835)   ->   1
same_namespace(4026531835, 4026532000)   ->   0

Input format

a, b: namespace inode ids (unsigned long).

Output format

1 if the ids are equal, else 0.

Starter code

int same_namespace(unsigned long a, unsigned long b) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.