![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| executing Unix script that contains CURL FTP commands from Peoplesoft Process Schedlr | sfedak | Shell Programming and Scripting | 2 | 02-18-2009 02:20 PM |
| child process state | smreddy | UNIX for Dummies Questions & Answers | 8 | 12-24-2007 12:51 AM |
| The State of Unix (Addict 3D) | iBot | UNIX and Linux RSS News | 0 | 06-18-2007 11:40 PM |
| The state of Unix - ZDNet.com blogs | iBot | UNIX and Linux RSS News | 0 | 06-18-2007 04:40 AM |
| Process State | ianlow | UNIX for Dummies Questions & Answers | 1 | 09-06-2006 11:11 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Unix script (sh): state of ftp process
Hi guys,
I’m writing a script in which I have to get file from a remote host by ftp. The problem is that the remote machine could be very slow, not connected or ok. To resolve this problem, I write this: [……] echo "verbose on" > ftprap.cmd echo "prompt " >> ftprap.cmd echo "ascii" >> ftprap.cmd echo "passive off" >> ftprap.cmd echo "mget * " >> ftprap.cmd echo "quit" >> ftprap.cmd ftp %IP < ./ftprap.cmd > ftp.log 2>&1 & PID_FTP=`echo $!` sleep 60 ps -o pid,tty,time,cmd,state|grep -E "$PID_FTP%S" >/dev/null 2>/dev/null if [ $? = 0 ] then kill -9 $PID_FTP >> ftp.log 2>&1 fi [……] To kill ftp only if it is blocked. It happens that even if ftp runs, ps shows me with state = S, that is sleeping!!! I try to run the script with “sleep 1”, while it’s transferring a lot of file, and I’m sure of this: ps shows ftp is sleeping and then the script kills it. I’m not so very expert about unix scripting, so I don’t’ know where I make mistakes. Would you help me? Thanks in advanced. |
|
||||
|
Hi pludi,
do you mean that if I use sleep I block my ftp command? According to avoid to wait forever if the remote host doesn’t work, I want to implement a sort of timeout, after this, if the ftp is blocked, I’ll kill it. If I use sleep, is ftp command in background stopped??? If it’s true, I’m a quite worried… I try to ping first the host (in the real case this code is in a loop for a list of hosts) but so many firewall bock ping and if ping has a positive result, this doesn’t unsure that ftp runs. ... I'm spending a lot of time about this problem.. and I'm getting crazier than I'm just! ![]() |
|
|||||
|
No, your sleep does not block the FTP command. Let's sidetrack into kernel process management for a bit:
Since their invention CPU cores can only execute one process at a time. This meant that a single process waiting for user input could block the whole system. So someone came up with the idea of time slices. Each process is allowed execution for a certain time. After that time it returns control to the kernel. All was good until some processes didn't return control on purpose. Most modern kernels use preempting instead. Again, each process is allocated execution time. After that time the OS kernel is woken via a timer interrupt (or sooner if the process gives it's rights back because it's waiting for something), the first process is sent into a sleep mode and another is given CPU time. The first process will continue when it's its turn. Now back to your case: you're starting the FTP process and send it into the background. It gets its time-slices just like any other process, but it's not executing the whole time. Sometimes other processes are executed, so ftp is marked as 'sleeping' or, better said, waiting for its turn again. If you only have one CPU core and get the current list with ps, all processes except for ps will (most likely) be marked as 'sleeping', since ps is currently using its allocated time to gather the stats. My suggestion for your problem would be:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|