I know that PID 1 is init. Now I would like to knom, can I replace init process ID to another one and assign to PID 1 a new process. If yes how can I do that?
The first process that is started at boot time receives PID 1.
The first process that is started at boot time has a job: it has to start all other processes, directly or indirectly. All processes¹ are ultimately descendants of this, since apart from the kernel running a program at boot time the only way a process gets created is that some process executed a system call to create a new process.
The process whose PID is 1 has a job: if a process dies while it has running child processes, the children's parent process ID is set to 1. When the children die, PID 1 should reap them, i.e. call the
wait system call, otherwise a zombie of the child process stays behind.
The various programs called
init (there are multiple implementations) perform both of these jobs.
The Linux kernel has a command line argument to change which executable is executed as the first process². It can be used to run any executable, but if that executable doesn't perform the jobs of init, the system isn't going to run normally. This feature is mostly used to enter a system repair mode, e.g. only running a shell on the console and nothing else.
Once the system has started normally, it is not possible to replace PID 1 because init doesn't die. Not only does init not die, because it's programmed to run forever (init is supposed to keep running until the system shuts down), but it even gets a special protection from signals that would kill other processes, such as SIGKILL.
Linux has a PID namespace feature that allows defining a subsystem with its own set of process IDs. The processes in a PID namespace have different PIDs when viewed from inside the namespace and from outside the namespace. The first process in the namespace gets PID 1 in the namespace. Outside the namespace it won't have PID 1 (unless init chose to enter a new PID namespace, but init doesn't do that because that would prevent it from doing its job).
¹ This isn't completely true, some kernels have other ways to launch a process. For example Linux launches
modprobe when some hardware is discovered under certain circumstances. But descendants of init account for a vast majority of processes.
² First after the initramfs or initrd.
In some ways init is special as noted by Gilles. If init dies, in most cases you get a kernel panic, which is why any reputable author of init will do much to avoid that happening. On the other hand it is much like any other program in that aside from dealing with zombie processes, you can actually use any program as init. cat works just fine but is not exactly useful. one of the ways that init is completely ordinary is that it can call execlve (exec and friends) which replaces one program with another using the same pid. this is used for example by initial root disks to run the real init after mounting the drive it will be run from.