linux - rm with ampersand in the end and without -
this interview question asked.
say have large script file, used compiling , cleaning purposes. assume have folder named folder @ same directory of file. in addition, in end of file have following code lines:
clean: rm -r -f folder & when try clean project, assume works fine. however, if remove ampersand , write this:
clean: rm -r -f folder then after try clean, you'll following error:
rm: cannot remove 'folder': directory not empty but if try clean 1 more time, folder cleaned desired.
i needed find possible reasons how happen. thing think of if have race between few threads running script. asked- "what if 1 thread run code?"
didn't see how problem happen 1 thread- seems mistaken , don't know why. what other scenarios can cause error above?
edit: in interview, assume following:
(1). there no ampersands in other places @ script file, rm code line wrote.
(2). new files not created in folder while performing rm
i'm glad fictional problem. using & way in makefiles bogus; no 1 doing in real world.
anyway, in typical interview scenario, need guess answer interviewer has in script. it's problem described incorrectly, @ least in question (and wouldn't unusual if wrong scenario presented in interview, too). question makes theoretical sense if error message happens & present , run make clean all. then, new build creates files prevent removal of directory. , that's why should not use & in makefile recipes.
Comments
Post a Comment