53.8k views
1 vote
Create a script that internally calls the Linux command 'ps aux' and saves the output to a file named unprocessed.txt (you do not need to append to an existing file, if a file already exists, simply overwrite it). The program should pause and display the following message to the screen: Press 'q' to exit or 'ctrl-c' to process the file and exit' If the user presses 'q', exit the program leaving the filename on the disk as 'unprocessed.txt'. If the user presses 'ctrl-c', then catch the signal (hint - covered in chapter 16) and rename the file to 'processed.txt' and then exit. You must build a signal handler to catch the ctrl-c signal and rename the file. g

User Linan
by
8.2k points

1 Answer

3 votes

Answer:

see explaination

Step-by-step explanation:

SIG{INT} = sub {

`mv unprocessed.txt processed.txt`;

print "\\";

exit;

};

`ps aux > unprocessed.txt`;

print "Press 'q' to exit or 'ctrl-c' to process the file and exit:\\";

$inp = <>;

if ($inp == 'q')

{

exit;

}

User LaSombra
by
8.3k points